|
1 | | -# Graph Framework Utils |
| 1 | +# Graph Framework Messages |
2 | 2 |
|
3 | | -Provides common utilities for the Graph Framework. |
4 | | - |
5 | | -_All utilities must be runnable on: Browser, NodeJS server, ReactNative._ |
6 | | - |
7 | | -## API |
8 | | - |
9 | | -- `generateId()` - generates a base58 encoded ID from a generated v4 UUID. |
10 | | - |
11 | | -```ts |
12 | | -import { generateId } from "graph-framework-utils"; |
13 | | - |
14 | | -const id = generateId(); |
15 | | -console.log(id); // Gw9uTVTnJdhtczyuzBkL3X |
16 | | -``` |
17 | | - |
18 | | -### Base58 utils |
19 | | - |
20 | | -- `encodeBase58` - encodes a given string (like the hyphen-stripped UUID) to base 58 |
21 | | - |
22 | | -```ts |
23 | | -import { v4 } from "uuid"; |
24 | | -import { encodeBase58 } from "graph-framework-utils/base58"; |
25 | | - |
26 | | -const uuid = v4(); // 92539817-7989-4083-ab80-e9c2b2b66669 |
27 | | -const stripped = uuid.replaceAll(/-/g, ""); // 9253981779894083ab80e9c2b2b66669 |
28 | | -const encoded = encodeBase58(dashesRemoved); |
29 | | -console.log(encoded); // K51CbDqxW35osbjPo5ZF77 |
30 | | -``` |
31 | | - |
32 | | -- `decodeBase58ToUUID` - decodes the given base58 encoded UUID back to its original UUID value |
33 | | - |
34 | | -```ts |
35 | | -import { v4 } from "uuid"; |
36 | | -import { decodeBase58ToUUID, encodeBase58 } from "graph-framework-utils/base58"; |
37 | | - |
38 | | -const uuid = v4(); // 92539817-7989-4083-ab80-e9c2b2b66669 |
39 | | -const stripped = uuid.replaceAll(/-/g, ""); // 9253981779894083ab80e9c2b2b66669 |
40 | | -const encoded = encodeBase58(dashesRemoved); // K51CbDqxW35osbjPo5ZF77 |
41 | | -const decoded = decodeBase58ToUUID(encoded); |
42 | | - |
43 | | -expect(encoded).toHaveLength(22); |
44 | | -expect(decoded).toEqual(uuid); |
45 | | -``` |
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 | | -``` |
| 3 | +Provides types related to messages for the Graph Framework |
0 commit comments