diff --git a/lib/feed-v1/get-msg-id.js b/lib/feed-v1/get-msg-id.js index 5a05c74..571799a 100644 --- a/lib/feed-v1/get-msg-id.js +++ b/lib/feed-v1/get-msg-id.js @@ -1,6 +1,6 @@ const blake3 = require('blake3') const base58 = require('bs58') -const stringify = require('fast-json-stable-stringify') +const stringify = require('canonicalize') /** * @typedef {import('./index').Msg} Msg diff --git a/lib/feed-v1/index.js b/lib/feed-v1/index.js index 135a43b..800f24a 100644 --- a/lib/feed-v1/index.js +++ b/lib/feed-v1/index.js @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0-only -const stringify = require('fast-json-stable-stringify') +const stringify = require('canonicalize') const ed25519 = require('ssb-keys/sodium') const base58 = require('bs58') const union = require('set.prototype.union') diff --git a/lib/feed-v1/represent-content.js b/lib/feed-v1/represent-content.js index 729be2d..cebf337 100644 --- a/lib/feed-v1/represent-content.js +++ b/lib/feed-v1/represent-content.js @@ -1,6 +1,6 @@ const blake3 = require('blake3') const base58 = require('bs58') -const stringify = require('fast-json-stable-stringify') +const stringify = require('canonicalize') /** * @param {any} content diff --git a/lib/feed-v1/validation.js b/lib/feed-v1/validation.js index 869a3b5..0a9b626 100644 --- a/lib/feed-v1/validation.js +++ b/lib/feed-v1/validation.js @@ -1,6 +1,6 @@ const base58 = require('bs58') const ed25519 = require('ssb-keys/sodium') -const stringify = require('fast-json-stable-stringify') +const stringify = require('canonicalize') const Tangle = require('./tangle') const representContent = require('./represent-content') diff --git a/package.json b/package.json index e1e76d6..8568ddd 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "async-append-only-log": "^4.3.10", "blake3": "^2.1.7", "bs58": "^5.0.0", - "fast-json-stable-stringify": "^2.1.0", + "canonicalize": "^2.0.0", "obz": "^1.1.0", "promisify-4loc": "^1.0.0", "push-stream": "^11.2.0", diff --git a/protospec.md b/protospec.md index cd086e5..835024f 100644 --- a/protospec.md +++ b/protospec.md @@ -65,9 +65,4 @@ Given the root msg ID, any peer can thus refer to the feed tangle, because the r ## JSON serialization -Whenever we need to serialize any JSON in the context of creating a Feed V1 message, we use the following rules: - -- Object fields are ordered alphabetically by field key -- No whitespace nor newliners are added -- No trailing commas are added -- UTF-8 encoding +Whenever we need to serialize any JSON in the context of creating a Feed V1 message, we follow the "JSON Canonicalization Scheme" (JSC) defined by [RFC 8785](https://tools.ietf.org/html/rfc8785).