Skip to content

Commit 795475f

Browse files
committed
feat(canonicalization): add to README
1 parent 571aa7c commit 795475f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

packages/graph-framework-utils/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,24 @@ const decoded = decodeBase58ToUUID(encoded);
4343
expect(encoded).toHaveLength(22);
4444
expect(decoded).toEqual(uuid);
4545
```
46+
47+
### JSC utils
48+
49+
- `canonicalize` - JSON canonicalize function. Creates crypto safe predictable canocalization of JSON as defined by RFC8785.
50+
51+
```ts
52+
import { canonicalize } from 'graph-framework-utils'
53+
54+
console.log(canonicalize(null)) // 'null'
55+
console.log(canonicalize(1)) // '1'
56+
console.log(canonicalize("test")) // "string"
57+
console.log(canonicalize(true)) // 'true'
58+
const json = {
59+
from_account: '543 232 625-3',
60+
to_account: '321 567 636-4',
61+
amount: 500,
62+
currency: 'USD',
63+
};
64+
console.log(canonicalize(json)) // '{"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}'
65+
console.log(canonicalize([1, 'text', null, true, false])) // '[1,"text",null,true,false]'
66+
```

packages/graph-framework-utils/src/jsc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export class InfinityNotAllowedError extends Error {
3131
* import { canonicalize } from 'graph-framework-utils'
3232
*
3333
* const json = {
34-
* from_account: '543 232 625-3',
35-
* to_account: '321 567 636-4',
36-
* amount: 500,
37-
* currency: 'USD',
34+
* from_account: '543 232 625-3',
35+
* to_account: '321 567 636-4',
36+
* amount: 500,
37+
* currency: 'USD',
3838
* };
3939
* console.log(canonicalize(json)) // '{"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}'
4040
* ```

0 commit comments

Comments
 (0)