@fangorn-network/sdk 2026.7.13 → 2026.7.24

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 (61) hide show
  1. package/README.md +23 -2
  2. package/lib/cli/cli.js +18 -11
  3. package/lib/cli/index.d.ts +13 -13
  4. package/lib/config.d.ts +93 -92
  5. package/lib/contracts/data-registry/abi.d.ts +207 -35
  6. package/lib/contracts/data-registry/index.js +4 -4
  7. package/lib/contracts/index.d.ts +3 -1
  8. package/lib/contracts/index.js +3 -1
  9. package/lib/contracts/settlement-registry/abi.d.ts +47 -0
  10. package/lib/contracts/settlement-registry/abi.js +48 -0
  11. package/lib/contracts/settlement-registry/index.d.ts +25 -0
  12. package/lib/contracts/settlement-registry/index.js +40 -0
  13. package/lib/crypto/aes.d.ts +1 -8
  14. package/lib/crypto/aes.js +2 -34
  15. package/lib/crypto/encryption.d.ts +112 -26
  16. package/lib/crypto/encryption.js +106 -22
  17. package/lib/engine/index.js +6 -3
  18. package/lib/fangorn.d.ts +4 -4
  19. package/lib/fangorn.js +20 -18
  20. package/lib/harness/index.d.ts +4 -3
  21. package/lib/harness/index.js +9 -3
  22. package/lib/index.d.ts +3 -3
  23. package/lib/index.js +3 -3
  24. package/lib/providers/storage/car.js +3 -2
  25. package/lib/providers/storage/pinata.js +27 -7
  26. package/lib/{roles/repo → repo}/index.d.ts +1 -1
  27. package/lib/{roles/repo → repo}/index.js +1 -1
  28. package/lib/test/testbed.d.ts +2 -2
  29. package/lib/test/testbed.js +1 -1
  30. package/package.json +4 -2
  31. package/lib/ crypto/constants.d.ts +0 -4
  32. package/lib/ crypto/constants.js +0 -5
  33. package/lib/ crypto/merkle.d.ts +0 -10
  34. package/lib/ crypto/merkle.js +0 -34
  35. package/lib/ crypto/utils.d.ts +0 -1
  36. package/lib/ crypto/utils.js +0 -1
  37. package/lib/builders/a2aCardBuilder.d.ts +0 -28
  38. package/lib/builders/a2aCardBuilder.js +0 -105
  39. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/_polyval.js +0 -218
  40. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/aes.js +0 -261
  41. package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/utils.js +0 -156
  42. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/curve.js +0 -299
  43. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/edwards.js +0 -532
  44. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/modular.js +0 -344
  45. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/montgomery.js +0 -137
  46. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/ed25519.js +0 -262
  47. package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/utils.js +0 -150
  48. package/lib/roles/index.d.ts +0 -1
  49. package/lib/roles/index.js +0 -1
  50. package/lib/test/car_smoke.d.ts +0 -1
  51. package/lib/test/car_smoke.js +0 -81
  52. package/lib/test/cleanup-embeddings-testdata.d.ts +0 -1
  53. package/lib/test/cleanup-embeddings-testdata.js +0 -75
  54. package/lib/test/index.d.ts +0 -10
  55. package/lib/test/index.js +0 -27
  56. package/lib/test/setup-embeddings-testdata.d.ts +0 -11
  57. package/lib/test/setup-embeddings-testdata.js +0 -155
  58. package/lib/utils/index.d.ts +0 -11
  59. package/lib/utils/index.js +0 -29
  60. package/lib/utils/manifest.d.ts +0 -23
  61. package/lib/utils/manifest.js +0 -77
@@ -1,9 +1,11 @@
1
1
  import { retrieveByCid, serialize } from "./utils.js";
2
- import { packCar } from "./car.js";
2
+ import { packCar } from "../../engine/car.js";
3
3
  import { keccak256, stringToBytes } from "viem";
4
4
  import { CID } from "multiformats/cid";
5
+ import { encode } from "multiformats/block";
5
6
  import { PinataSDK } from "pinata";
6
7
  import * as dagCbor from "@ipld/dag-cbor";
8
+ import { sha256 } from "multiformats/hashes/sha2";
7
9
 
8
10
  //#region src/providers/storage/pinata.ts
9
11
  const RAW_CODE = 85;
@@ -66,9 +68,26 @@ var PinataBackend = class {
66
68
  */
67
69
  async putMany(items) {
68
70
  if (items.length === 0) return {};
69
- const { bytes, uriByName } = await packCar(items);
71
+ const blocks = [];
72
+ const uriByName = {};
73
+ for (const item of items) {
74
+ const block = await encode({
75
+ value: item.data,
76
+ codec: dagCbor,
77
+ hasher: sha256
78
+ });
79
+ blocks.push(block);
80
+ uriByName[item.name] = `ipfs://${block.cid.toString()}`;
81
+ }
82
+ const rootBlock = await encode({
83
+ value: uriByName,
84
+ codec: dagCbor,
85
+ hasher: sha256
86
+ });
87
+ blocks.push(rootBlock);
88
+ const bytes = await packCar(rootBlock.cid, blocks);
70
89
  await withUploadRetry(`car[${items.length.toString()}f/${(bytes.length / 1e6).toFixed(1)}MB]`, async () => {
71
- const file = new File([bytes], "data.car", { type: "application/vnd.ipld.car" });
90
+ const file = new File([bytes.buffer], "data.car", { type: "application/vnd.ipld.car" });
72
91
  await this.pinata.upload.public.file(file).car();
73
92
  });
74
93
  return uriByName;
@@ -148,7 +167,8 @@ var PinataBackend = class {
148
167
  if (attempts === 0) break;
149
168
  await new Promise((resolve) => setTimeout(resolve, 1e3));
150
169
  }
151
- throw new Error(`Pinata SDK failed to retrieve block ${uri} after multiple attempts. Internal Error: ${lastError?.message || lastError}`);
170
+ const internalMessage = lastError instanceof Error ? lastError.message : typeof lastError === "string" ? lastError : String(lastError ?? "");
171
+ throw new Error(`Pinata SDK failed to retrieve block ${uri} after multiple attempts. Internal Error: ${internalMessage}`);
152
172
  }
153
173
  static async getStatic(uri, gateway) {
154
174
  return retrieveByCid(uri, gateway);
@@ -157,15 +177,15 @@ var PinataBackend = class {
157
177
  const formattedRoot = stateRoot.toLowerCase();
158
178
  for (let i = 0; i < retries; i++) {
159
179
  const response = await this.pinata.files.public.list().keyvalues({ stateRoot: formattedRoot });
160
- if (response && response.files && response.files.length > 0) return response.files[0].cid;
180
+ if (response.files.length > 0) return response.files[0].cid;
161
181
  if (i < retries - 1) {
162
182
  console.warn(`
163
- [Pinata] Indexing lag detected for root ${formattedRoot}. Retrying in ${delay * (i + 1)}ms...
183
+ [Pinata] Indexing lag detected for root ${formattedRoot}. Retrying in ${(delay * (i + 1)).toString()}ms...
164
184
  `);
165
185
  await new Promise((resolve) => setTimeout(resolve, delay * (i + 1)));
166
186
  }
167
187
  }
168
- throw new Error(`No matching IPFS CID found for state root: ${stateRoot} after ${retries} retrieval attempts.`);
188
+ throw new Error(`No matching IPFS CID found for state root: ${stateRoot} after ${retries.toString()} retrieval attempts.`);
169
189
  }
170
190
  async delete(uri) {
171
191
  await this.pinata.files.public.delete([uri]);
@@ -1,6 +1,6 @@
1
1
  import { Address, Hex } from "viem";
2
2
 
3
- //#region src/roles/repo/index.d.ts
3
+ //#region src/repo/index.d.ts
4
4
 
5
5
  /**
6
6
  * The local working repo — a `.fangorn/` directory, the analogue of `.git/`.
@@ -1,7 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
2
  import { join } from "path";
3
3
 
4
- //#region src/roles/repo/index.ts
4
+ //#region src/repo/index.ts
5
5
  /**
6
6
  * The local working repo — a `.fangorn/` directory, the analogue of `.git/`.
7
7
  *
@@ -21,7 +21,7 @@ declare class TestBed {
21
21
  txHash: `0x${string}`;
22
22
  alreadyInitialized: false;
23
23
  }>;
24
- upload(index: number, namespace: string, payload: any, name: string): Promise<{
24
+ upload(index: number, namespace: string, payload: unknown, name: string): Promise<{
25
25
  payloadCid: string;
26
26
  commitCid: string;
27
27
  txHash: `0x${string}`;
@@ -29,7 +29,7 @@ declare class TestBed {
29
29
  uploadBatch(index: number, namespace: string, vertices: {
30
30
  id: string;
31
31
  tag: string;
32
- payload: any;
32
+ payload: unknown;
33
33
  }[], edges?: {
34
34
  rel: string;
35
35
  from: string;
@@ -6,7 +6,7 @@ var TestBed = class TestBed {
6
6
  this.f_list = f_list;
7
7
  }
8
8
  static init(sks) {
9
- let f_list = [];
9
+ const f_list = [];
10
10
  sks.forEach((sk) => {
11
11
  f_list.push(Fangorn.create({
12
12
  privateKey: sk,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fangorn-network/sdk",
3
- "version": "2026.07.13",
4
- "description": "A zero-knowledge conditional access control framework",
3
+ "version": "2026.07.24",
4
+ "description": "Git for knowledge graphs",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/fangorn-network/fangorn.git"
@@ -61,6 +61,8 @@
61
61
  "@ipld/car": "^5.4.6",
62
62
  "@ipld/dag-cbor": "^10.0.1",
63
63
  "@ipld/unixfs": "^3.0.0",
64
+ "@noble/ciphers": "^1.3.0",
65
+ "@noble/curves": "^1.9.7",
64
66
  "@noble/hashes": "^2.2.0",
65
67
  "@noir-lang/noir_js": "1.0.0-beta.22",
66
68
  "@semaphore-protocol/group": "^4.14.2",
@@ -1,4 +0,0 @@
1
- //#region src/ crypto/constants.d.ts
2
- declare const TREE_DEPTH = 8;
3
- //#endregion
4
- export { TREE_DEPTH };
@@ -1,5 +0,0 @@
1
- //#region src/ crypto/constants.ts
2
- const TREE_DEPTH = 8;
3
-
4
- //#endregion
5
- export { TREE_DEPTH };
@@ -1,10 +0,0 @@
1
- //#region src/ crypto/merkle.d.ts
2
- declare function hashCidToField(cid: string): bigint;
3
- declare function getProof(layers: bigint[][], index: number): {
4
- path: bigint[];
5
- indices: number[];
6
- };
7
- declare function fieldToHex(field: bigint): `0x${string}`;
8
- declare function hexToField(hex: string): bigint;
9
- //#endregion
10
- export { fieldToHex, getProof, hashCidToField, hexToField };
@@ -1,34 +0,0 @@
1
- import { TREE_DEPTH } from "./constants.js";
2
-
3
- //#region src/ crypto/merkle.ts
4
- function hashCidToField(cid) {
5
- const bytes = new TextEncoder().encode(cid);
6
- let value = 0n;
7
- for (let i = 0; i < Math.min(bytes.length, 31); i++) value = value << 8n | BigInt(bytes[i]);
8
- return value;
9
- }
10
- function getProof(layers, index) {
11
- const path = [];
12
- const indices = [];
13
- for (let i = 0; i < TREE_DEPTH; i++) {
14
- const isRight = index % 2 === 1;
15
- const siblingIndex = isRight ? index - 1 : index + 1;
16
- path.push(layers[i][siblingIndex] ?? 0n);
17
- indices.push(isRight ? 1 : 0);
18
- index = Math.floor(index / 2);
19
- }
20
- return {
21
- path,
22
- indices
23
- };
24
- }
25
- function fieldToHex(field) {
26
- return `0x${field.toString(16).padStart(64, "0")}`;
27
- }
28
- function hexToField(hex) {
29
- const cleanHex = hex.startsWith("0x") ? hex : `0x${hex}`;
30
- return BigInt(cleanHex);
31
- }
32
-
33
- //#endregion
34
- export { fieldToHex, getProof, hashCidToField, hexToField };
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };
@@ -1,28 +0,0 @@
1
- import { AgentCard } from "@a2a-js/sdk";
2
-
3
- //#region src/builders/a2aCardBuilder.d.ts
4
- declare class AgentCardBuilder {
5
- private card;
6
- name(name: string): this;
7
- description(description: string): this;
8
- version(version: string): this;
9
- url(url: string): this;
10
- protocolVersion(protocolVersion: string): this;
11
- capabilities(opts: {
12
- streaming?: boolean;
13
- pushNotifications?: boolean;
14
- stateTransitionHistory?: boolean;
15
- }): this;
16
- streaming(enabled?: boolean): this;
17
- pushNotifications(enabled?: boolean): this;
18
- stateTransitionHistory(enabled?: boolean): this;
19
- inputModes(modes: string[]): this;
20
- outputModes(modes: string[]): this;
21
- addSkill(id: string, name: string, description: string, tags: string[], examples?: string[]): this;
22
- provider(organization: string, url: string): this;
23
- documentationUrl(url: string): this;
24
- build(): AgentCard;
25
- }
26
- declare const agentCardBuilder: () => AgentCardBuilder;
27
- //#endregion
28
- export { AgentCardBuilder, agentCardBuilder };
@@ -1,105 +0,0 @@
1
- //#region src/builders/a2aCardBuilder.ts
2
- var AgentCardBuilder = class {
3
- card = {
4
- capabilities: {
5
- streaming: false,
6
- pushNotifications: false,
7
- stateTransitionHistory: false
8
- },
9
- defaultInputModes: ["text/plain", "application/json"],
10
- defaultOutputModes: ["text/plain", "application/json"],
11
- skills: []
12
- };
13
- name(name) {
14
- this.card.name = name;
15
- return this;
16
- }
17
- description(description) {
18
- this.card.description = description;
19
- return this;
20
- }
21
- version(version) {
22
- this.card.version = version;
23
- return this;
24
- }
25
- url(url) {
26
- this.card.url = url;
27
- return this;
28
- }
29
- protocolVersion(protocolVersion) {
30
- this.card.protocolVersion = protocolVersion;
31
- return this;
32
- }
33
- capabilities(opts) {
34
- this.card.capabilities = {
35
- ...this.card.capabilities,
36
- ...opts
37
- };
38
- return this;
39
- }
40
- streaming(enabled = true) {
41
- this.card.capabilities = {
42
- ...this.card.capabilities,
43
- streaming: enabled
44
- };
45
- return this;
46
- }
47
- pushNotifications(enabled = true) {
48
- this.card.capabilities = {
49
- ...this.card.capabilities,
50
- pushNotifications: enabled
51
- };
52
- return this;
53
- }
54
- stateTransitionHistory(enabled = true) {
55
- this.card.capabilities = {
56
- ...this.card.capabilities,
57
- stateTransitionHistory: enabled
58
- };
59
- return this;
60
- }
61
- inputModes(modes) {
62
- this.card.defaultInputModes = modes;
63
- return this;
64
- }
65
- outputModes(modes) {
66
- this.card.defaultOutputModes = modes;
67
- return this;
68
- }
69
- addSkill(id, name, description, tags, examples) {
70
- const skill = {
71
- id,
72
- name,
73
- description,
74
- tags
75
- };
76
- if (examples) skill.examples = examples;
77
- this.card.skills ??= [];
78
- this.card.skills.push(skill);
79
- return this;
80
- }
81
- provider(organization, url) {
82
- this.card.provider = {
83
- organization,
84
- url
85
- };
86
- return this;
87
- }
88
- documentationUrl(url) {
89
- this.card.documentationUrl = url;
90
- return this;
91
- }
92
- build() {
93
- for (const field of [
94
- "name",
95
- "description",
96
- "version",
97
- "url"
98
- ]) if (!this.card[field]) throw new Error(`AgentCard requires '${field}'`);
99
- return this.card;
100
- }
101
- };
102
- const agentCardBuilder = () => new AgentCardBuilder();
103
-
104
- //#endregion
105
- export { AgentCardBuilder, agentCardBuilder };
@@ -1,218 +0,0 @@
1
- import { abytes, aexists, aoutput, clean, copyBytes, createView, toBytes, u32 } from "./utils.js";
2
-
3
- //#region node_modules/.pnpm/@noble+ciphers@1.3.0/node_modules/@noble/ciphers/esm/_polyval.js
4
- /**
5
- * GHash from AES-GCM and its little-endian "mirror image" Polyval from AES-SIV.
6
- *
7
- * Implemented in terms of GHash with conversion function for keys
8
- * GCM GHASH from
9
- * [NIST SP800-38d](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf),
10
- * SIV from
11
- * [RFC 8452](https://datatracker.ietf.org/doc/html/rfc8452).
12
- *
13
- * GHASH modulo: x^128 + x^7 + x^2 + x + 1
14
- * POLYVAL modulo: x^128 + x^127 + x^126 + x^121 + 1
15
- *
16
- * @module
17
- */
18
- const BLOCK_SIZE = 16;
19
- const ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
20
- const ZEROS32 = u32(ZEROS16);
21
- const POLY = 225;
22
- const mul2 = (s0, s1, s2, s3) => {
23
- const hiBit = s3 & 1;
24
- return {
25
- s3: s2 << 31 | s3 >>> 1,
26
- s2: s1 << 31 | s2 >>> 1,
27
- s1: s0 << 31 | s1 >>> 1,
28
- s0: s0 >>> 1 ^ POLY << 24 & -(hiBit & 1)
29
- };
30
- };
31
- const swapLE = (n) => (n >>> 0 & 255) << 24 | (n >>> 8 & 255) << 16 | (n >>> 16 & 255) << 8 | n >>> 24 & 255 | 0;
32
- /**
33
- * `mulX_POLYVAL(ByteReverse(H))` from spec
34
- * @param k mutated in place
35
- */
36
- function _toGHASHKey(k) {
37
- k.reverse();
38
- const hiBit = k[15] & 1;
39
- let carry = 0;
40
- for (let i = 0; i < k.length; i++) {
41
- const t = k[i];
42
- k[i] = t >>> 1 | carry;
43
- carry = (t & 1) << 7;
44
- }
45
- k[0] ^= -hiBit & 225;
46
- return k;
47
- }
48
- const estimateWindow = (bytes) => {
49
- if (bytes > 64 * 1024) return 8;
50
- if (bytes > 1024) return 4;
51
- return 2;
52
- };
53
- var GHASH = class {
54
- constructor(key, expectedLength) {
55
- this.blockLen = BLOCK_SIZE;
56
- this.outputLen = BLOCK_SIZE;
57
- this.s0 = 0;
58
- this.s1 = 0;
59
- this.s2 = 0;
60
- this.s3 = 0;
61
- this.finished = false;
62
- key = toBytes(key);
63
- abytes(key, 16);
64
- const kView = createView(key);
65
- let k0 = kView.getUint32(0, false);
66
- let k1 = kView.getUint32(4, false);
67
- let k2 = kView.getUint32(8, false);
68
- let k3 = kView.getUint32(12, false);
69
- const doubles = [];
70
- for (let i = 0; i < 128; i++) {
71
- doubles.push({
72
- s0: swapLE(k0),
73
- s1: swapLE(k1),
74
- s2: swapLE(k2),
75
- s3: swapLE(k3)
76
- });
77
- ({s0: k0, s1: k1, s2: k2, s3: k3} = mul2(k0, k1, k2, k3));
78
- }
79
- const W = estimateWindow(expectedLength || 1024);
80
- if (![
81
- 1,
82
- 2,
83
- 4,
84
- 8
85
- ].includes(W)) throw new Error("ghash: invalid window size, expected 2, 4 or 8");
86
- this.W = W;
87
- const windows = 128 / W;
88
- const windowSize = this.windowSize = 2 ** W;
89
- const items = [];
90
- for (let w = 0; w < windows; w++) for (let byte = 0; byte < windowSize; byte++) {
91
- let s0 = 0, s1 = 0, s2 = 0, s3 = 0;
92
- for (let j = 0; j < W; j++) {
93
- if (!(byte >>> W - j - 1 & 1)) continue;
94
- const { s0: d0, s1: d1, s2: d2, s3: d3 } = doubles[W * w + j];
95
- s0 ^= d0, s1 ^= d1, s2 ^= d2, s3 ^= d3;
96
- }
97
- items.push({
98
- s0,
99
- s1,
100
- s2,
101
- s3
102
- });
103
- }
104
- this.t = items;
105
- }
106
- _updateBlock(s0, s1, s2, s3) {
107
- s0 ^= this.s0, s1 ^= this.s1, s2 ^= this.s2, s3 ^= this.s3;
108
- const { W, t, windowSize } = this;
109
- let o0 = 0, o1 = 0, o2 = 0, o3 = 0;
110
- const mask = (1 << W) - 1;
111
- let w = 0;
112
- for (const num of [
113
- s0,
114
- s1,
115
- s2,
116
- s3
117
- ]) for (let bytePos = 0; bytePos < 4; bytePos++) {
118
- const byte = num >>> 8 * bytePos & 255;
119
- for (let bitPos = 8 / W - 1; bitPos >= 0; bitPos--) {
120
- const bit = byte >>> W * bitPos & mask;
121
- const { s0: e0, s1: e1, s2: e2, s3: e3 } = t[w * windowSize + bit];
122
- o0 ^= e0, o1 ^= e1, o2 ^= e2, o3 ^= e3;
123
- w += 1;
124
- }
125
- }
126
- this.s0 = o0;
127
- this.s1 = o1;
128
- this.s2 = o2;
129
- this.s3 = o3;
130
- }
131
- update(data) {
132
- aexists(this);
133
- data = toBytes(data);
134
- abytes(data);
135
- const b32 = u32(data);
136
- const blocks = Math.floor(data.length / BLOCK_SIZE);
137
- const left = data.length % BLOCK_SIZE;
138
- for (let i = 0; i < blocks; i++) this._updateBlock(b32[i * 4 + 0], b32[i * 4 + 1], b32[i * 4 + 2], b32[i * 4 + 3]);
139
- if (left) {
140
- ZEROS16.set(data.subarray(blocks * BLOCK_SIZE));
141
- this._updateBlock(ZEROS32[0], ZEROS32[1], ZEROS32[2], ZEROS32[3]);
142
- clean(ZEROS32);
143
- }
144
- return this;
145
- }
146
- destroy() {
147
- const { t } = this;
148
- for (const elm of t) elm.s0 = 0, elm.s1 = 0, elm.s2 = 0, elm.s3 = 0;
149
- }
150
- digestInto(out) {
151
- aexists(this);
152
- aoutput(out, this);
153
- this.finished = true;
154
- const { s0, s1, s2, s3 } = this;
155
- const o32 = u32(out);
156
- o32[0] = s0;
157
- o32[1] = s1;
158
- o32[2] = s2;
159
- o32[3] = s3;
160
- return out;
161
- }
162
- digest() {
163
- const res = new Uint8Array(BLOCK_SIZE);
164
- this.digestInto(res);
165
- this.destroy();
166
- return res;
167
- }
168
- };
169
- var Polyval = class extends GHASH {
170
- constructor(key, expectedLength) {
171
- key = toBytes(key);
172
- abytes(key);
173
- const ghKey = _toGHASHKey(copyBytes(key));
174
- super(ghKey, expectedLength);
175
- clean(ghKey);
176
- }
177
- update(data) {
178
- data = toBytes(data);
179
- aexists(this);
180
- const b32 = u32(data);
181
- const left = data.length % BLOCK_SIZE;
182
- const blocks = Math.floor(data.length / BLOCK_SIZE);
183
- for (let i = 0; i < blocks; i++) this._updateBlock(swapLE(b32[i * 4 + 3]), swapLE(b32[i * 4 + 2]), swapLE(b32[i * 4 + 1]), swapLE(b32[i * 4 + 0]));
184
- if (left) {
185
- ZEROS16.set(data.subarray(blocks * BLOCK_SIZE));
186
- this._updateBlock(swapLE(ZEROS32[3]), swapLE(ZEROS32[2]), swapLE(ZEROS32[1]), swapLE(ZEROS32[0]));
187
- clean(ZEROS32);
188
- }
189
- return this;
190
- }
191
- digestInto(out) {
192
- aexists(this);
193
- aoutput(out, this);
194
- this.finished = true;
195
- const { s0, s1, s2, s3 } = this;
196
- const o32 = u32(out);
197
- o32[0] = s0;
198
- o32[1] = s1;
199
- o32[2] = s2;
200
- o32[3] = s3;
201
- return out.reverse();
202
- }
203
- };
204
- function wrapConstructorWithKey(hashCons) {
205
- const hashC = (msg, key) => hashCons(key, msg.length).update(toBytes(msg)).digest();
206
- const tmp = hashCons(new Uint8Array(16), 0);
207
- hashC.outputLen = tmp.outputLen;
208
- hashC.blockLen = tmp.blockLen;
209
- hashC.create = (key, expectedLength) => hashCons(key, expectedLength);
210
- return hashC;
211
- }
212
- /** GHash MAC for AES-GCM. */
213
- const ghash = wrapConstructorWithKey((key, expectedLength) => new GHASH(key, expectedLength));
214
- /** Polyval MAC for AES-SIV. */
215
- const polyval = wrapConstructorWithKey((key, expectedLength) => new Polyval(key, expectedLength));
216
-
217
- //#endregion
218
- export { ghash };