MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / serializeDeterministically

Function serializeDeterministically

lib/src/commit.ts:118–140  ·  view source on GitHub ↗
(
  commit: CommitPreSigned | Commit,
)

Source from the content-addressed store, hash-verified

116 * https://docs.atomicdata.dev/core/json-ad.html#canonicalized-json-ad
117 */
118export function serializeDeterministically(
119 commit: CommitPreSigned | Commit,
120): string {
121 // Remove empty arrays, objects, false values from root
122 if (commit.remove?.length == 0) {
123 delete commit.remove;
124 }
125 if (commit.set?.length == 0) {
126 delete commit.remove;
127 }
128 if (commit.destroy == false) {
129 delete commit.destroy;
130 }
131 replaceKey(commit, 'createdAt', urls.properties.commit.createdAt);
132 replaceKey(commit, 'subject', urls.properties.commit.subject);
133 replaceKey(commit, 'set', urls.properties.commit.set);
134 replaceKey(commit, 'signer', urls.properties.commit.signer);
135 replaceKey(commit, 'signature', urls.properties.commit.signature);
136 replaceKey(commit, 'remove', urls.properties.commit.remove);
137 replaceKey(commit, 'destroy', urls.properties.commit.destroy);
138 commit[urls.properties.isA] = [urls.classes.commit];
139 return stringify(commit);
140}
141
142/** Creates a signature for a Commit using the private Key of some Agent. */
143export const signAt = async (

Callers 2

postCommitFunction · 0.90
signAtFunction · 0.85

Calls 1

replaceKeyFunction · 0.85

Tested by

no test coverage detected