@graphprotocol/hypergraph 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/connect/auth-storage.d.ts.map +1 -0
  4. package/dist/connect/create-app-identity.d.ts.map +1 -0
  5. package/dist/connect/create-auth-url.d.ts.map +1 -0
  6. package/dist/connect/create-auth-url.js +35 -0
  7. package/dist/connect/create-auth-url.js.map +1 -0
  8. package/dist/connect/create-callback-params.d.ts.map +1 -0
  9. package/dist/connect/create-callback-params.js +17 -0
  10. package/dist/connect/create-callback-params.js.map +1 -0
  11. package/dist/connect/create-identity-keys.d.ts.map +1 -0
  12. package/dist/connect/identity-encryption.d.ts.map +1 -0
  13. package/dist/connect/index.d.ts.map +1 -0
  14. package/dist/connect/login.d.ts.map +1 -0
  15. package/dist/connect/parse-callback-params.d.ts.map +1 -0
  16. package/dist/connect/parse-callback-params.js +63 -0
  17. package/dist/connect/parse-callback-params.js.map +1 -0
  18. package/dist/connect/prove-ownership.d.ts.map +1 -0
  19. package/dist/connect/types.d.ts +57 -0
  20. package/dist/connect/types.d.ts.map +1 -0
  21. package/dist/connect/types.js +24 -0
  22. package/dist/connect/types.js.map +1 -0
  23. package/dist/entity/create.d.ts.map +1 -0
  24. package/dist/entity/decodedEntitiesCache.d.ts.map +1 -0
  25. package/dist/entity/delete.d.ts.map +1 -0
  26. package/dist/entity/entity.d.ts.map +1 -0
  27. package/dist/entity/entityRelationParentsMap.d.ts.map +1 -0
  28. package/dist/entity/findMany.d.ts.map +1 -0
  29. package/dist/entity/findMany.js +436 -0
  30. package/dist/entity/findMany.js.map +1 -0
  31. package/dist/entity/findOne.d.ts.map +1 -0
  32. package/dist/entity/getEntityRelations.d.ts.map +1 -0
  33. package/dist/entity/index.d.ts.map +1 -0
  34. package/dist/entity/relationParentsMap.d.ts.map +1 -0
  35. package/dist/entity/removeRelation.d.ts.map +1 -0
  36. package/dist/entity/types.d.ts +79 -0
  37. package/dist/entity/types.d.ts.map +1 -0
  38. package/dist/entity/types.js +2 -0
  39. package/dist/entity/types.js.map +1 -0
  40. package/dist/entity/update.d.ts.map +1 -0
  41. package/dist/identity/auth-storage.d.ts.map +1 -0
  42. package/dist/identity/get-verified-identity.d.ts.map +1 -0
  43. package/dist/identity/identity-encryption.d.ts.map +1 -0
  44. package/dist/identity/index.d.ts.map +1 -0
  45. package/dist/identity/logout.d.ts.map +1 -0
  46. package/dist/identity/prove-ownership.d.ts.map +1 -0
  47. package/dist/inboxes/create-inbox.d.ts.map +1 -0
  48. package/dist/inboxes/get-list-inboxes.d.ts.map +1 -0
  49. package/dist/inboxes/index.d.ts.map +1 -0
  50. package/dist/inboxes/merge-messages.d.ts.map +1 -0
  51. package/dist/inboxes/message-encryption.d.ts.map +1 -0
  52. package/dist/inboxes/message-validation.d.ts.map +1 -0
  53. package/dist/inboxes/prepare-message.d.ts +31 -0
  54. package/dist/inboxes/prepare-message.d.ts.map +1 -0
  55. package/dist/inboxes/recover-inbox-creator.d.ts.map +1 -0
  56. package/dist/inboxes/recover-inbox-message-signer.d.ts.map +1 -0
  57. package/dist/inboxes/send-message.d.ts.map +1 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/messages/index.d.ts.map +1 -0
  60. package/dist/messages/signed-update-message.d.ts.map +1 -0
  61. package/dist/messages/types.d.ts.map +1 -0
  62. package/dist/space-events/accept-invitation.d.ts.map +1 -0
  63. package/dist/space-events/apply-event.d.ts.map +1 -0
  64. package/dist/space-events/create-inbox.d.ts.map +1 -0
  65. package/dist/space-events/create-invitation.d.ts.map +1 -0
  66. package/dist/space-events/create-space.d.ts.map +1 -0
  67. package/dist/space-events/delete-space.d.ts.map +1 -0
  68. package/dist/space-events/hash-event.d.ts.map +1 -0
  69. package/dist/space-events/index.d.ts.map +1 -0
  70. package/dist/space-info/decrypt-space-info.d.ts.map +1 -0
  71. package/dist/space-info/encrypt-and-sign-space-info.d.ts.map +1 -0
  72. package/dist/space-info/index.d.ts.map +1 -0
  73. package/dist/store-connect.d.ts.map +1 -0
  74. package/dist/store.d.ts.map +1 -0
  75. package/dist/type/type.d.ts.map +1 -0
  76. package/dist/utils/automergeId.d.ts +9 -0
  77. package/dist/utils/automergeId.d.ts.map +1 -0
  78. package/dist/utils/automergeId.js +17 -0
  79. package/dist/utils/automergeId.js.map +1 -0
  80. package/dist/utils/generateId.d.ts +15 -0
  81. package/dist/utils/generateId.d.ts.map +1 -0
  82. package/dist/utils/generateId.js +18 -0
  83. package/dist/utils/generateId.js.map +1 -0
  84. package/dist/utils/index.d.ts.map +1 -0
  85. package/package.json +35 -0
  86. package/src/connect/auth-storage.ts +67 -0
  87. package/src/connect/create-app-identity.ts +16 -0
  88. package/src/connect/create-auth-url.ts +42 -0
  89. package/src/connect/create-callback-params.ts +30 -0
  90. package/src/connect/create-identity-keys.ts +20 -0
  91. package/src/connect/identity-encryption.ts +232 -0
  92. package/src/connect/index.ts +10 -0
  93. package/src/connect/login.ts +114 -0
  94. package/src/connect/parse-auth-params.ts +37 -0
  95. package/src/connect/parse-callback-params.ts +67 -0
  96. package/src/connect/prove-ownership.ts +58 -0
  97. package/src/connect/types.ts +67 -0
  98. package/src/entity/create.ts +58 -0
  99. package/src/entity/decodedEntitiesCache.ts +38 -0
  100. package/src/entity/delete.ts +52 -0
  101. package/src/entity/entity.ts +26 -0
  102. package/src/entity/entityRelationParentsMap.ts +6 -0
  103. package/src/entity/findMany.ts +506 -0
  104. package/src/entity/findOne.ts +34 -0
  105. package/src/entity/getEntityRelations.ts +45 -0
  106. package/src/entity/hasValidTypesProperty.ts +8 -0
  107. package/src/entity/index.ts +8 -0
  108. package/src/entity/relationParentsMap.ts +6 -0
  109. package/src/entity/removeRelation.ts +21 -0
  110. package/src/entity/test.ts +0 -0
  111. package/src/entity/types.ts +100 -0
  112. package/src/entity/update.ts +58 -0
  113. package/src/entity/variant-schema.ts +677 -0
  114. package/src/identity/auth-storage.ts +57 -0
  115. package/src/identity/get-verified-identity.ts +53 -0
  116. package/src/identity/identity-encryption.ts +140 -0
  117. package/src/identity/index.ts +6 -0
  118. package/src/identity/logout.ts +8 -0
  119. package/src/identity/prove-ownership.ts +58 -0
  120. package/src/identity/types.ts +44 -0
  121. package/src/inboxes/create-inbox.ts +102 -0
  122. package/src/inboxes/get-list-inboxes.ts +52 -0
  123. package/src/inboxes/index.ts +10 -0
  124. package/src/inboxes/merge-messages.ts +28 -0
  125. package/src/inboxes/message-encryption.ts +35 -0
  126. package/src/inboxes/message-validation.ts +66 -0
  127. package/src/inboxes/prepare-message.ts +85 -0
  128. package/src/inboxes/recover-inbox-creator.ts +29 -0
  129. package/src/inboxes/recover-inbox-message-signer.ts +42 -0
  130. package/src/inboxes/send-message.ts +75 -0
  131. package/src/inboxes/types.ts +9 -0
  132. package/src/index.ts +13 -0
  133. package/src/key/create-key.ts +27 -0
  134. package/src/key/decrypt-key.ts +19 -0
  135. package/src/key/encrypt-key.ts +27 -0
  136. package/src/key/index.ts +4 -0
  137. package/src/key/key-box.ts +31 -0
  138. package/src/messages/decrypt-message.ts +13 -0
  139. package/src/messages/encrypt-message.ts +14 -0
  140. package/src/messages/index.ts +5 -0
  141. package/src/messages/serialize.ts +24 -0
  142. package/src/messages/signed-update-message.ts +84 -0
  143. package/src/messages/types.ts +506 -0
  144. package/src/space-events/accept-invitation.ts +36 -0
  145. package/src/space-events/apply-event.ts +150 -0
  146. package/src/space-events/create-inbox.ts +56 -0
  147. package/src/space-events/create-invitation.ts +41 -0
  148. package/src/space-events/create-space.ts +35 -0
  149. package/src/space-events/delete-space.ts +36 -0
  150. package/src/space-events/hash-event.ts +10 -0
  151. package/src/space-events/index.ts +8 -0
  152. package/src/space-events/types.ts +137 -0
  153. package/src/space-info/decrypt-space-info.ts +22 -0
  154. package/src/space-info/encrypt-and-sign-space-info.ts +50 -0
  155. package/src/space-info/index.ts +3 -0
  156. package/src/space-info/types.ts +7 -0
  157. package/src/store-connect.ts +504 -0
  158. package/src/store.ts +493 -0
  159. package/src/type/type.ts +25 -0
  160. package/src/types.ts +47 -0
  161. package/src/utils/assertExhaustive.ts +3 -0
  162. package/src/utils/automergeId.ts +18 -0
  163. package/src/utils/base58.ts +74 -0
  164. package/src/utils/generateId.ts +18 -0
  165. package/src/utils/hexBytesAddressUtils.ts +25 -0
  166. package/src/utils/index.ts +8 -0
  167. package/src/utils/internal/base58Utils.ts +47 -0
  168. package/src/utils/internal/deep-merge.ts +38 -0
  169. package/src/utils/isRelationField.ts +9 -0
  170. package/src/utils/jsc.ts +94 -0
  171. package/src/utils/stringToUint8Array.ts +9 -0
@@ -0,0 +1,8 @@
1
+ export * from './assertExhaustive.js';
2
+ export * from './automergeId.js';
3
+ export * from './base58.js';
4
+ export * from './generateId.js';
5
+ export * from './hexBytesAddressUtils.js';
6
+ export * from './isRelationField.js';
7
+ export * from './jsc.js';
8
+ export * from './stringToUint8Array.js';
@@ -0,0 +1,47 @@
1
+ export const BASE58_ALLOWED_CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
2
+
3
+ export function decodeBase58(str: string) {
4
+ let x = BigInt(0);
5
+ for (let i = 0; i < str.length; i++) {
6
+ const charIndex = BASE58_ALLOWED_CHARS.indexOf(str[i]);
7
+ if (charIndex < 0) {
8
+ throw new Error('Invalid Base58 character');
9
+ }
10
+ x = x * 58n + BigInt(charIndex);
11
+ }
12
+
13
+ const bytes: number[] = [];
14
+ while (x > 0) {
15
+ bytes.push(Number(x % 256n));
16
+ x = x >> 8n;
17
+ }
18
+
19
+ bytes.reverse();
20
+ // Pad to 16 bytes for a UUID
21
+ while (bytes.length < 16) {
22
+ bytes.unshift(0);
23
+ }
24
+
25
+ return new Uint8Array(bytes);
26
+ }
27
+
28
+ export function encodeBase58(data: Uint8Array) {
29
+ let x = BigInt(0);
30
+ for (const byte of data) {
31
+ x = (x << 8n) + BigInt(byte);
32
+ }
33
+
34
+ let encoded = '';
35
+ while (x > 0) {
36
+ const remainder = x % 58n;
37
+ x = x / 58n;
38
+ encoded = BASE58_ALLOWED_CHARS[Number(remainder)] + encoded;
39
+ }
40
+
41
+ // deal with leading zeros (0x00 bytes)
42
+ for (let i = 0; i < data.length && data[i] === 0; i++) {
43
+ encoded = `1${encoded}`;
44
+ }
45
+
46
+ return encoded;
47
+ }
@@ -0,0 +1,38 @@
1
+ // A “plain object” is any non-null object that isn’t an array
2
+ const isPlainObject = (obj: unknown): obj is Record<string, unknown> =>
3
+ typeof obj === 'object' && obj !== null && !Array.isArray(obj);
4
+
5
+ /**
6
+ * Deeply merges two plain‐object types T and U,
7
+ * returning a new object that has properties of both.
8
+ * Arrays or other non‐object values in `source` simply overwrite.
9
+ */
10
+ export const deepMerge = <T extends Record<string, unknown>, U extends Record<string, unknown>>(
11
+ target: T,
12
+ source: U,
13
+ ): T & U => {
14
+ // Start with a shallow clone of target
15
+ const result = { ...target } as T & U;
16
+
17
+ for (const key of Object.keys(source) as (keyof U)[]) {
18
+ const srcVal = source[key];
19
+ // biome-ignore lint/suspicious/noExplicitAny: good enough
20
+ const tgtVal = (target as any)[key];
21
+
22
+ if (isPlainObject(srcVal) && isPlainObject(tgtVal)) {
23
+ // Both sides are plain objects → recurse
24
+ // biome-ignore lint/suspicious/noExplicitAny: good enough
25
+ result[key] = deepMerge(tgtVal as Record<string, unknown>, srcVal as Record<string, unknown>) as any;
26
+ } else if (isPlainObject(srcVal)) {
27
+ // Source is object but target missing or not object → clone source
28
+ // biome-ignore lint/suspicious/noExplicitAny: good enough
29
+ result[key] = deepMerge({} as Record<string, unknown>, srcVal as Record<string, unknown>) as any;
30
+ } else {
31
+ // Non‐objects (including arrays) overwrite
32
+ // biome-ignore lint/suspicious/noExplicitAny: good enough
33
+ result[key] = srcVal as any;
34
+ }
35
+ }
36
+
37
+ return result;
38
+ };
@@ -0,0 +1,9 @@
1
+ import type * as Schema from 'effect/Schema';
2
+
3
+ export const isRelationField = (field: Schema.Schema.All | Schema.PropertySignature.All<PropertyKey>) => {
4
+ // TODO: improve this check
5
+ if (field.ast._tag === 'TupleType') {
6
+ return true;
7
+ }
8
+ return false;
9
+ };
@@ -0,0 +1,94 @@
1
+ export class NaNNotAllowedError extends Error {
2
+ constructor() {
3
+ super('NaN is not allowed');
4
+ }
5
+ }
6
+ export class InfinityNotAllowedError extends Error {
7
+ constructor() {
8
+ super('Infinity is not allowed');
9
+ }
10
+ }
11
+
12
+ /**
13
+ * JSON canonicalize function.
14
+ * Creates crypto safe predictable canocalization of JSON as defined by RFC8785.
15
+ *
16
+ * @see https://tools.ietf.org/html/rfc8785
17
+ * @see https://www.rfc-editor.org/rfc/rfc8785
18
+ *
19
+ * @example <caption>Primitive values</caption>
20
+ * ```ts
21
+ * import { canonicalize } from '@graph-framework/utils'
22
+ *
23
+ * console.log(canonicalize(null)) // 'null'
24
+ * console.log(canonicalize(1)) // '1'
25
+ * console.log(canonicalize("test")) // "string"
26
+ * console.log(canonicalize(true)) // 'true'
27
+ * ```
28
+ *
29
+ * @example <caption>Objects</caption>
30
+ * ```
31
+ * import { canonicalize } from '@graph-framework/utils'
32
+ *
33
+ * const json = {
34
+ * from_account: '543 232 625-3',
35
+ * to_account: '321 567 636-4',
36
+ * amount: 500,
37
+ * currency: 'USD',
38
+ * };
39
+ * console.log(canonicalize(json)) // '{"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}'
40
+ * ```
41
+ *
42
+ * @example <caption>Arrays</caption>
43
+ * ```ts
44
+ * import { canonicalize } from '@graph-framework/utils'
45
+ *
46
+ * console.log(canonicalize([1, 'text', null, true, false])) // '[1,"text",null,true,false]'
47
+ * ```
48
+ *
49
+ * @param object object to JSC canonicalize
50
+ * @throws NaNNotAllowedError if given object is of type number, but is not a valid number
51
+ * @throws InfinityNotAllowedError if given object is of type number, but is the infinite number
52
+ */
53
+ export function canonicalize<T = unknown>(object: T): string {
54
+ if (typeof object === 'number' && Number.isNaN(object)) {
55
+ throw new NaNNotAllowedError();
56
+ }
57
+ if (typeof object === 'number' && !Number.isFinite(object)) {
58
+ throw new InfinityNotAllowedError();
59
+ }
60
+
61
+ if (object === null || typeof object !== 'object') {
62
+ return JSON.stringify(object);
63
+ }
64
+
65
+ // biome-ignore lint/suspicious/noExplicitAny: typeof T is unknown, cast to any to check
66
+ if ((object as any).toJSON instanceof Function) {
67
+ // biome-ignore lint/suspicious/noExplicitAny: typeof T is unknown, cast to any to check
68
+ return canonicalize((object as any).toJSON());
69
+ }
70
+
71
+ if (Array.isArray(object)) {
72
+ const values = object.reduce((t, cv) => {
73
+ if (cv === undefined || typeof cv === 'symbol') {
74
+ return t; // Skip undefined and symbol values entirely
75
+ }
76
+ const comma = t.length === 0 ? '' : ',';
77
+ return `${t}${comma}${canonicalize(cv)}`;
78
+ }, '');
79
+ return `[${values}]`;
80
+ }
81
+
82
+ const values = Object.keys(object)
83
+ .sort()
84
+ .reduce((t, cv) => {
85
+ // biome-ignore lint/suspicious/noExplicitAny: typeof T is unknown, cast to any to check
86
+ if ((object as any)[cv] === undefined || typeof (object as any)[cv] === 'symbol') {
87
+ return t;
88
+ }
89
+ const comma = t.length === 0 ? '' : ',';
90
+ // biome-ignore lint/suspicious/noExplicitAny: typeof T is unknown, cast to any to check
91
+ return `${t}${comma}${canonicalize(cv)}:${canonicalize((object as any)[cv])}`;
92
+ }, '');
93
+ return `{${values}}`;
94
+ }
@@ -0,0 +1,9 @@
1
+ const encoder = new TextEncoder();
2
+ const decoder = new TextDecoder();
3
+ export const stringToUint8Array = (str: string): Uint8Array => {
4
+ return encoder.encode(str);
5
+ };
6
+
7
+ export const uint8ArrayToString = (uint8Array: Uint8Array): string => {
8
+ return decoder.decode(uint8Array);
9
+ };