@fangorn-network/sdk 2026.7.13 → 2026.7.14
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.
- package/README.md +23 -2
- package/lib/cli/cli.js +18 -11
- package/lib/cli/index.d.ts +13 -13
- package/lib/config.d.ts +93 -92
- package/lib/contracts/data-registry/abi.d.ts +207 -35
- package/lib/contracts/data-registry/index.js +4 -4
- package/lib/contracts/index.d.ts +3 -1
- package/lib/contracts/index.js +3 -1
- package/lib/contracts/settlement-registry/abi.d.ts +47 -0
- package/lib/contracts/settlement-registry/abi.js +48 -0
- package/lib/contracts/settlement-registry/index.d.ts +25 -0
- package/lib/contracts/settlement-registry/index.js +40 -0
- package/lib/crypto/aes.d.ts +1 -8
- package/lib/crypto/aes.js +2 -34
- package/lib/crypto/encryption.d.ts +112 -26
- package/lib/crypto/encryption.js +105 -21
- package/lib/engine/index.js +5 -2
- package/lib/fangorn.d.ts +3 -3
- package/lib/fangorn.js +19 -13
- package/lib/harness/index.d.ts +4 -3
- package/lib/harness/index.js +9 -3
- package/lib/index.d.ts +2 -3
- package/lib/index.js +2 -3
- package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/_polyval.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/aes.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/utils.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/curve.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/edwards.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/modular.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/montgomery.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/ed25519.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/utils.js +1 -1
- package/lib/providers/storage/car.js +2 -1
- package/lib/providers/storage/pinata.js +5 -4
- package/lib/{roles/repo → repo}/index.d.ts +1 -1
- package/lib/{roles/repo → repo}/index.js +1 -1
- package/lib/test/testbed.d.ts +2 -2
- package/lib/test/testbed.js +1 -1
- package/package.json +2 -2
- package/lib/ crypto/constants.d.ts +0 -4
- package/lib/ crypto/constants.js +0 -5
- package/lib/ crypto/merkle.d.ts +0 -10
- package/lib/ crypto/merkle.js +0 -34
- package/lib/ crypto/utils.d.ts +0 -1
- package/lib/ crypto/utils.js +0 -1
- package/lib/builders/a2aCardBuilder.d.ts +0 -28
- package/lib/builders/a2aCardBuilder.js +0 -105
- package/lib/roles/index.d.ts +0 -1
- package/lib/roles/index.js +0 -1
- package/lib/test/car_smoke.d.ts +0 -1
- package/lib/test/car_smoke.js +0 -81
- package/lib/test/cleanup-embeddings-testdata.d.ts +0 -1
- package/lib/test/cleanup-embeddings-testdata.js +0 -75
- package/lib/test/index.d.ts +0 -10
- package/lib/test/index.js +0 -27
- package/lib/test/setup-embeddings-testdata.d.ts +0 -11
- package/lib/test/setup-embeddings-testdata.js +0 -155
- package/lib/utils/index.d.ts +0 -11
- package/lib/utils/index.js +0 -29
- package/lib/utils/manifest.d.ts +0 -23
- package/lib/utils/manifest.js +0 -77
|
@@ -1,38 +1,210 @@
|
|
|
1
1
|
//#region src/contracts/data-registry/abi.d.ts
|
|
2
|
-
declare const DATA_REGISTRY_ABI:
|
|
3
|
-
inputs:
|
|
4
|
-
name:
|
|
5
|
-
type:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
inputs:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
2
|
+
declare const DATA_REGISTRY_ABI: readonly [{
|
|
3
|
+
readonly inputs: readonly [];
|
|
4
|
+
readonly name: "AlreadyRegistered";
|
|
5
|
+
readonly type: "error";
|
|
6
|
+
}, {
|
|
7
|
+
readonly inputs: readonly [];
|
|
8
|
+
readonly name: "NotRegistered";
|
|
9
|
+
readonly type: "error";
|
|
10
|
+
}, {
|
|
11
|
+
readonly inputs: readonly [];
|
|
12
|
+
readonly name: "PublisherSuspendedErr";
|
|
13
|
+
readonly type: "error";
|
|
14
|
+
}, {
|
|
15
|
+
readonly inputs: readonly [];
|
|
16
|
+
readonly name: "RegistrationFeeRequired";
|
|
17
|
+
readonly type: "error";
|
|
18
|
+
}, {
|
|
19
|
+
readonly inputs: readonly [];
|
|
20
|
+
readonly name: "StaleStateRoot";
|
|
21
|
+
readonly type: "error";
|
|
22
|
+
}, {
|
|
23
|
+
readonly inputs: readonly [];
|
|
24
|
+
readonly name: "Unauthorized";
|
|
25
|
+
readonly type: "error";
|
|
26
|
+
}, {
|
|
27
|
+
readonly anonymous: false;
|
|
28
|
+
readonly inputs: readonly [{
|
|
29
|
+
readonly indexed: true;
|
|
30
|
+
readonly internalType: "address";
|
|
31
|
+
readonly name: "publisher";
|
|
32
|
+
readonly type: "address";
|
|
33
|
+
}, {
|
|
34
|
+
readonly indexed: false;
|
|
35
|
+
readonly internalType: "bytes32";
|
|
36
|
+
readonly name: "initial_root";
|
|
37
|
+
readonly type: "bytes32";
|
|
38
|
+
}];
|
|
39
|
+
readonly name: "PublisherRegistered";
|
|
40
|
+
readonly type: "event";
|
|
41
|
+
}, {
|
|
42
|
+
readonly anonymous: false;
|
|
43
|
+
readonly inputs: readonly [{
|
|
44
|
+
readonly indexed: true;
|
|
45
|
+
readonly internalType: "address";
|
|
46
|
+
readonly name: "publisher";
|
|
47
|
+
readonly type: "address";
|
|
48
|
+
}, {
|
|
49
|
+
readonly indexed: false;
|
|
50
|
+
readonly internalType: "bytes32";
|
|
51
|
+
readonly name: "current_root";
|
|
52
|
+
readonly type: "bytes32";
|
|
53
|
+
}];
|
|
54
|
+
readonly name: "PublisherReactivated";
|
|
55
|
+
readonly type: "event";
|
|
56
|
+
}, {
|
|
57
|
+
readonly anonymous: false;
|
|
58
|
+
readonly inputs: readonly [{
|
|
59
|
+
readonly indexed: true;
|
|
60
|
+
readonly internalType: "address";
|
|
61
|
+
readonly name: "publisher";
|
|
62
|
+
readonly type: "address";
|
|
63
|
+
}];
|
|
64
|
+
readonly name: "PublisherSuspended";
|
|
65
|
+
readonly type: "event";
|
|
66
|
+
}, {
|
|
67
|
+
readonly anonymous: false;
|
|
68
|
+
readonly inputs: readonly [{
|
|
69
|
+
readonly indexed: false;
|
|
70
|
+
readonly internalType: "uint256";
|
|
71
|
+
readonly name: "fee";
|
|
72
|
+
readonly type: "uint256";
|
|
73
|
+
}];
|
|
74
|
+
readonly name: "RegistrationFeeChanged";
|
|
75
|
+
readonly type: "event";
|
|
76
|
+
}, {
|
|
77
|
+
readonly anonymous: false;
|
|
78
|
+
readonly inputs: readonly [{
|
|
79
|
+
readonly indexed: true;
|
|
80
|
+
readonly internalType: "address";
|
|
81
|
+
readonly name: "publisher";
|
|
82
|
+
readonly type: "address";
|
|
83
|
+
}, {
|
|
84
|
+
readonly indexed: true;
|
|
85
|
+
readonly internalType: "bytes32";
|
|
86
|
+
readonly name: "old_root";
|
|
87
|
+
readonly type: "bytes32";
|
|
88
|
+
}, {
|
|
89
|
+
readonly indexed: true;
|
|
90
|
+
readonly internalType: "bytes32";
|
|
91
|
+
readonly name: "new_root";
|
|
92
|
+
readonly type: "bytes32";
|
|
93
|
+
}];
|
|
94
|
+
readonly name: "StateCommitted";
|
|
95
|
+
readonly type: "event";
|
|
96
|
+
}, {
|
|
97
|
+
readonly inputs: readonly [];
|
|
98
|
+
readonly name: "admin";
|
|
99
|
+
readonly outputs: readonly [{
|
|
100
|
+
readonly internalType: "address";
|
|
101
|
+
readonly name: "";
|
|
102
|
+
readonly type: "address";
|
|
103
|
+
}];
|
|
104
|
+
readonly stateMutability: "view";
|
|
105
|
+
readonly type: "function";
|
|
106
|
+
}, {
|
|
107
|
+
readonly inputs: readonly [{
|
|
108
|
+
readonly internalType: "bytes32";
|
|
109
|
+
readonly name: "old_root";
|
|
110
|
+
readonly type: "bytes32";
|
|
111
|
+
}, {
|
|
112
|
+
readonly internalType: "bytes32";
|
|
113
|
+
readonly name: "new_root";
|
|
114
|
+
readonly type: "bytes32";
|
|
115
|
+
}];
|
|
116
|
+
readonly name: "commitStateRoot";
|
|
117
|
+
readonly outputs: readonly [];
|
|
118
|
+
readonly stateMutability: "nonpayable";
|
|
119
|
+
readonly type: "function";
|
|
120
|
+
}, {
|
|
121
|
+
readonly inputs: readonly [{
|
|
122
|
+
readonly internalType: "address";
|
|
123
|
+
readonly name: "publisher";
|
|
124
|
+
readonly type: "address";
|
|
125
|
+
}];
|
|
126
|
+
readonly name: "getNamespaceHead";
|
|
127
|
+
readonly outputs: readonly [{
|
|
128
|
+
readonly internalType: "bytes32";
|
|
129
|
+
readonly name: "";
|
|
130
|
+
readonly type: "bytes32";
|
|
131
|
+
}];
|
|
132
|
+
readonly stateMutability: "view";
|
|
133
|
+
readonly type: "function";
|
|
134
|
+
}, {
|
|
135
|
+
readonly inputs: readonly [{
|
|
136
|
+
readonly internalType: "address";
|
|
137
|
+
readonly name: "publisher";
|
|
138
|
+
readonly type: "address";
|
|
139
|
+
}];
|
|
140
|
+
readonly name: "getPublisherStatus";
|
|
141
|
+
readonly outputs: readonly [{
|
|
142
|
+
readonly internalType: "uint8";
|
|
143
|
+
readonly name: "";
|
|
144
|
+
readonly type: "uint8";
|
|
145
|
+
}];
|
|
146
|
+
readonly stateMutability: "view";
|
|
147
|
+
readonly type: "function";
|
|
148
|
+
}, {
|
|
149
|
+
readonly inputs: readonly [{
|
|
150
|
+
readonly internalType: "address";
|
|
151
|
+
readonly name: "publisher";
|
|
152
|
+
readonly type: "address";
|
|
153
|
+
}];
|
|
154
|
+
readonly name: "isRegistered";
|
|
155
|
+
readonly outputs: readonly [{
|
|
156
|
+
readonly internalType: "bool";
|
|
157
|
+
readonly name: "";
|
|
158
|
+
readonly type: "bool";
|
|
159
|
+
}];
|
|
160
|
+
readonly stateMutability: "view";
|
|
161
|
+
readonly type: "function";
|
|
162
|
+
}, {
|
|
163
|
+
readonly inputs: readonly [];
|
|
164
|
+
readonly name: "publisherCount";
|
|
165
|
+
readonly outputs: readonly [{
|
|
166
|
+
readonly internalType: "uint64";
|
|
167
|
+
readonly name: "";
|
|
168
|
+
readonly type: "uint64";
|
|
169
|
+
}];
|
|
170
|
+
readonly stateMutability: "view";
|
|
171
|
+
readonly type: "function";
|
|
172
|
+
}, {
|
|
173
|
+
readonly inputs: readonly [];
|
|
174
|
+
readonly name: "register";
|
|
175
|
+
readonly outputs: readonly [];
|
|
176
|
+
readonly stateMutability: "payable";
|
|
177
|
+
readonly type: "function";
|
|
178
|
+
}, {
|
|
179
|
+
readonly inputs: readonly [];
|
|
180
|
+
readonly name: "registrationFee";
|
|
181
|
+
readonly outputs: readonly [{
|
|
182
|
+
readonly internalType: "uint256";
|
|
183
|
+
readonly name: "";
|
|
184
|
+
readonly type: "uint256";
|
|
185
|
+
}];
|
|
186
|
+
readonly stateMutability: "view";
|
|
187
|
+
readonly type: "function";
|
|
188
|
+
}, {
|
|
189
|
+
readonly inputs: readonly [{
|
|
190
|
+
readonly internalType: "uint256";
|
|
191
|
+
readonly name: "fee";
|
|
192
|
+
readonly type: "uint256";
|
|
193
|
+
}];
|
|
194
|
+
readonly name: "setRegistrationFee";
|
|
195
|
+
readonly outputs: readonly [];
|
|
196
|
+
readonly stateMutability: "nonpayable";
|
|
197
|
+
readonly type: "function";
|
|
198
|
+
}, {
|
|
199
|
+
readonly inputs: readonly [{
|
|
200
|
+
readonly internalType: "address";
|
|
201
|
+
readonly name: "publisher";
|
|
202
|
+
readonly type: "address";
|
|
203
|
+
}];
|
|
204
|
+
readonly name: "suspendPublisher";
|
|
205
|
+
readonly outputs: readonly [];
|
|
206
|
+
readonly stateMutability: "nonpayable";
|
|
207
|
+
readonly type: "function";
|
|
208
|
+
}];
|
|
37
209
|
//#endregion
|
|
38
210
|
export { DATA_REGISTRY_ABI };
|
|
@@ -8,11 +8,12 @@ let PublisherStatus = /* @__PURE__ */ function(PublisherStatus$1) {
|
|
|
8
8
|
return PublisherStatus$1;
|
|
9
9
|
}({});
|
|
10
10
|
function decodeStateCommitted(log) {
|
|
11
|
+
if (log.args.old_root === void 0 || log.args.new_root === void 0) throw new Error("Malformed log event: missing state roots");
|
|
11
12
|
return {
|
|
12
13
|
oldRoot: log.args.old_root,
|
|
13
14
|
newRoot: log.args.new_root,
|
|
14
15
|
blockNumber: log.blockNumber,
|
|
15
|
-
logId: `${log.transactionHash}:${
|
|
16
|
+
logId: `${log.transactionHash}:${log.logIndex.toString()}`
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
var DataRegistryClient = class {
|
|
@@ -52,7 +53,7 @@ var DataRegistryClient = class {
|
|
|
52
53
|
chain,
|
|
53
54
|
account,
|
|
54
55
|
gas: gas * 130n / 100n,
|
|
55
|
-
maxFeePerGas:
|
|
56
|
+
maxFeePerGas: fees.maxFeePerGas * 3n,
|
|
56
57
|
maxPriorityFeePerGas: fees.maxPriorityFeePerGas,
|
|
57
58
|
value
|
|
58
59
|
});
|
|
@@ -89,13 +90,12 @@ var DataRegistryClient = class {
|
|
|
89
90
|
* Reads the explicit enum lifecycle state from the registry status machine.
|
|
90
91
|
*/
|
|
91
92
|
async getPublisherStatus(publisher) {
|
|
92
|
-
|
|
93
|
+
return await this.publicClient.readContract({
|
|
93
94
|
address: this.contractAddress,
|
|
94
95
|
abi: DATA_REGISTRY_ABI,
|
|
95
96
|
functionName: "getPublisherStatus",
|
|
96
97
|
args: [publisher]
|
|
97
98
|
});
|
|
98
|
-
return Number(status);
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
101
|
* Helper boolean view returning true if a publisher can currently commit data.
|
package/lib/contracts/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
|
|
2
2
|
import { DataRegistryClient, PublisherStatus, StateCommittedLog } from "./data-registry/index.js";
|
|
3
|
-
|
|
3
|
+
import { SettlementRegistryClient } from "./settlement-registry/index.js";
|
|
4
|
+
import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
|
|
5
|
+
export { DATA_REGISTRY_ABI, DataRegistryClient, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient, StateCommittedLog };
|
package/lib/contracts/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { DATA_REGISTRY_ABI } from "./data-registry/abi.js";
|
|
2
2
|
import { DataRegistryClient, PublisherStatus } from "./data-registry/index.js";
|
|
3
|
+
import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
|
|
4
|
+
import { SettlementRegistryClient } from "./settlement-registry/index.js";
|
|
3
5
|
|
|
4
|
-
export { DATA_REGISTRY_ABI, DataRegistryClient, PublisherStatus };
|
|
6
|
+
export { DATA_REGISTRY_ABI, DataRegistryClient, PublisherStatus, SETTLEMENT_REGISTRY_ABI, SettlementRegistryClient };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/contracts/settlement-registry/abi.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The Settlement Registry: the on-chain rail that gates who can read a
|
|
4
|
+
* settlement-priced resource. A consumer settles (pays) for a `resourceId`
|
|
5
|
+
* out of band; the access worker (and anyone else) then reads `isSettled` to
|
|
6
|
+
* decide whether to release the bytes.
|
|
7
|
+
*
|
|
8
|
+
* This is the exact ABI the deployed access worker calls
|
|
9
|
+
* (`webworker/src/index.ts`), kept in lock-step so the SDK and worker agree on
|
|
10
|
+
* the settlement check. Read-only here: the pay/settle write path is a separate
|
|
11
|
+
* payment rail (x402 / ERC-3009 USDC) and is out of band for the SDK.
|
|
12
|
+
*/
|
|
13
|
+
declare const SETTLEMENT_REGISTRY_ABI: readonly [{
|
|
14
|
+
readonly inputs: readonly [{
|
|
15
|
+
readonly internalType: "address";
|
|
16
|
+
readonly name: "stealth_address";
|
|
17
|
+
readonly type: "address";
|
|
18
|
+
}, {
|
|
19
|
+
readonly internalType: "bytes32";
|
|
20
|
+
readonly name: "resource_id";
|
|
21
|
+
readonly type: "bytes32";
|
|
22
|
+
}];
|
|
23
|
+
readonly name: "isSettled";
|
|
24
|
+
readonly outputs: readonly [{
|
|
25
|
+
readonly internalType: "bool";
|
|
26
|
+
readonly name: "";
|
|
27
|
+
readonly type: "bool";
|
|
28
|
+
}];
|
|
29
|
+
readonly stateMutability: "view";
|
|
30
|
+
readonly type: "function";
|
|
31
|
+
}, {
|
|
32
|
+
readonly inputs: readonly [{
|
|
33
|
+
readonly internalType: "bytes32";
|
|
34
|
+
readonly name: "resource_id";
|
|
35
|
+
readonly type: "bytes32";
|
|
36
|
+
}];
|
|
37
|
+
readonly name: "getPrice";
|
|
38
|
+
readonly outputs: readonly [{
|
|
39
|
+
readonly internalType: "uint256";
|
|
40
|
+
readonly name: "";
|
|
41
|
+
readonly type: "uint256";
|
|
42
|
+
}];
|
|
43
|
+
readonly stateMutability: "view";
|
|
44
|
+
readonly type: "function";
|
|
45
|
+
}];
|
|
46
|
+
//#endregion
|
|
47
|
+
export { SETTLEMENT_REGISTRY_ABI };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/contracts/settlement-registry/abi.ts
|
|
2
|
+
/**
|
|
3
|
+
* The Settlement Registry: the on-chain rail that gates who can read a
|
|
4
|
+
* settlement-priced resource. A consumer settles (pays) for a `resourceId`
|
|
5
|
+
* out of band; the access worker (and anyone else) then reads `isSettled` to
|
|
6
|
+
* decide whether to release the bytes.
|
|
7
|
+
*
|
|
8
|
+
* This is the exact ABI the deployed access worker calls
|
|
9
|
+
* (`webworker/src/index.ts`), kept in lock-step so the SDK and worker agree on
|
|
10
|
+
* the settlement check. Read-only here: the pay/settle write path is a separate
|
|
11
|
+
* payment rail (x402 / ERC-3009 USDC) and is out of band for the SDK.
|
|
12
|
+
*/
|
|
13
|
+
const SETTLEMENT_REGISTRY_ABI = [{
|
|
14
|
+
inputs: [{
|
|
15
|
+
internalType: "address",
|
|
16
|
+
name: "stealth_address",
|
|
17
|
+
type: "address"
|
|
18
|
+
}, {
|
|
19
|
+
internalType: "bytes32",
|
|
20
|
+
name: "resource_id",
|
|
21
|
+
type: "bytes32"
|
|
22
|
+
}],
|
|
23
|
+
name: "isSettled",
|
|
24
|
+
outputs: [{
|
|
25
|
+
internalType: "bool",
|
|
26
|
+
name: "",
|
|
27
|
+
type: "bool"
|
|
28
|
+
}],
|
|
29
|
+
stateMutability: "view",
|
|
30
|
+
type: "function"
|
|
31
|
+
}, {
|
|
32
|
+
inputs: [{
|
|
33
|
+
internalType: "bytes32",
|
|
34
|
+
name: "resource_id",
|
|
35
|
+
type: "bytes32"
|
|
36
|
+
}],
|
|
37
|
+
name: "getPrice",
|
|
38
|
+
outputs: [{
|
|
39
|
+
internalType: "uint256",
|
|
40
|
+
name: "",
|
|
41
|
+
type: "uint256"
|
|
42
|
+
}],
|
|
43
|
+
stateMutability: "view",
|
|
44
|
+
type: "function"
|
|
45
|
+
}];
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { SETTLEMENT_REGISTRY_ABI };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Address, Hex, PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
//#region src/contracts/settlement-registry/index.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Read-only client for the Settlement Registry — the settlement rail behind
|
|
7
|
+
* gated reads. A resource is identified by its `resourceId` (bytes32, the same
|
|
8
|
+
* value produced by `resourceId(owner, schemaId, name)` in utils/manifest and
|
|
9
|
+
* bound into a sealed field's HKDF key).
|
|
10
|
+
*
|
|
11
|
+
* `getPrice(resourceId) === 0` means the resource is free (the worker lets any
|
|
12
|
+
* signed request through); a non-zero price means the caller must have settled.
|
|
13
|
+
* The pay/settle write path is a separate payment rail and is not modeled here.
|
|
14
|
+
*/
|
|
15
|
+
declare class SettlementRegistryClient {
|
|
16
|
+
private contractAddress;
|
|
17
|
+
private publicClient;
|
|
18
|
+
constructor(contractAddress: Address, publicClient: PublicClient);
|
|
19
|
+
/** True if `stealthAddress` has settled for `resourceId`. */
|
|
20
|
+
isSettled(stealthAddress: Address, resourceId: Hex): Promise<boolean>;
|
|
21
|
+
/** Price of `resourceId` in the settlement token's smallest unit; 0 = free. */
|
|
22
|
+
getPrice(resourceId: Hex): Promise<bigint>;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { SettlementRegistryClient };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SETTLEMENT_REGISTRY_ABI } from "./abi.js";
|
|
2
|
+
|
|
3
|
+
//#region src/contracts/settlement-registry/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Read-only client for the Settlement Registry — the settlement rail behind
|
|
6
|
+
* gated reads. A resource is identified by its `resourceId` (bytes32, the same
|
|
7
|
+
* value produced by `resourceId(owner, schemaId, name)` in utils/manifest and
|
|
8
|
+
* bound into a sealed field's HKDF key).
|
|
9
|
+
*
|
|
10
|
+
* `getPrice(resourceId) === 0` means the resource is free (the worker lets any
|
|
11
|
+
* signed request through); a non-zero price means the caller must have settled.
|
|
12
|
+
* The pay/settle write path is a separate payment rail and is not modeled here.
|
|
13
|
+
*/
|
|
14
|
+
var SettlementRegistryClient = class {
|
|
15
|
+
constructor(contractAddress, publicClient) {
|
|
16
|
+
this.contractAddress = contractAddress;
|
|
17
|
+
this.publicClient = publicClient;
|
|
18
|
+
}
|
|
19
|
+
/** True if `stealthAddress` has settled for `resourceId`. */
|
|
20
|
+
async isSettled(stealthAddress, resourceId) {
|
|
21
|
+
return this.publicClient.readContract({
|
|
22
|
+
address: this.contractAddress,
|
|
23
|
+
abi: SETTLEMENT_REGISTRY_ABI,
|
|
24
|
+
functionName: "isSettled",
|
|
25
|
+
args: [stealthAddress, resourceId]
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** Price of `resourceId` in the settlement token's smallest unit; 0 = free. */
|
|
29
|
+
async getPrice(resourceId) {
|
|
30
|
+
return this.publicClient.readContract({
|
|
31
|
+
address: this.contractAddress,
|
|
32
|
+
abi: SETTLEMENT_REGISTRY_ABI,
|
|
33
|
+
functionName: "getPrice",
|
|
34
|
+
args: [resourceId]
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { SettlementRegistryClient };
|
package/lib/crypto/aes.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { AesEncryptedData } from "./types.js";
|
|
2
|
-
|
|
3
1
|
//#region src/crypto/aes.d.ts
|
|
4
2
|
/** AES-256 key length, in bytes. */
|
|
5
3
|
declare const AES_KEY_LENGTH = 32;
|
|
@@ -17,10 +15,5 @@ declare function aesGcmEncrypt(key: Uint8Array, plaintext: Uint8Array, nonce: Ui
|
|
|
17
15
|
* {@link aesGcmEncrypt}. Throws if the tag does not verify.
|
|
18
16
|
*/
|
|
19
17
|
declare function aesGcmDecrypt(key: Uint8Array, sealed: Uint8Array, nonce: Uint8Array): Uint8Array;
|
|
20
|
-
declare function encryptData(data: string | Uint8Array): Promise<{
|
|
21
|
-
encryptedData: AesEncryptedData;
|
|
22
|
-
keyMaterial: Uint8Array<ArrayBuffer>;
|
|
23
|
-
}>;
|
|
24
|
-
declare function decryptData(encryptedData: AesEncryptedData, keyMaterial: Uint8Array<ArrayBuffer>): Promise<Uint8Array>;
|
|
25
18
|
//#endregion
|
|
26
|
-
export { AES_KEY_LENGTH, GCM_NONCE_LENGTH, GCM_TAG_LENGTH, aesGcmDecrypt, aesGcmEncrypt
|
|
19
|
+
export { AES_KEY_LENGTH, GCM_NONCE_LENGTH, GCM_TAG_LENGTH, aesGcmDecrypt, aesGcmEncrypt };
|
package/lib/crypto/aes.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { gcm } from "../node_modules
|
|
2
|
-
import { getRandomValues } from "./rand.js";
|
|
1
|
+
import { gcm } from "../node_modules/@noble/ciphers/esm/aes.js";
|
|
3
2
|
|
|
4
3
|
//#region src/crypto/aes.ts
|
|
5
4
|
/** AES-256 key length, in bytes. */
|
|
@@ -22,37 +21,6 @@ function aesGcmEncrypt(key, plaintext, nonce) {
|
|
|
22
21
|
function aesGcmDecrypt(key, sealed, nonce) {
|
|
23
22
|
return gcm(key, nonce).decrypt(sealed);
|
|
24
23
|
}
|
|
25
|
-
async function encryptData(data) {
|
|
26
|
-
const salt = getRandomValues(new Uint8Array(16));
|
|
27
|
-
const iv = getRandomValues(new Uint8Array(GCM_NONCE_LENGTH));
|
|
28
|
-
const keyMaterial = getRandomValues(new Uint8Array(AES_KEY_LENGTH));
|
|
29
|
-
const sealed = aesGcmEncrypt(keyMaterial, typeof data === "string" ? new TextEncoder().encode(data) : data, iv);
|
|
30
|
-
const ciphertext = sealed.slice(0, sealed.length - GCM_TAG_LENGTH);
|
|
31
|
-
const authTag = sealed.slice(sealed.length - GCM_TAG_LENGTH);
|
|
32
|
-
return {
|
|
33
|
-
encryptedData: {
|
|
34
|
-
ciphertext: new Uint8Array(ciphertext),
|
|
35
|
-
iv,
|
|
36
|
-
authTag: new Uint8Array(authTag),
|
|
37
|
-
salt
|
|
38
|
-
},
|
|
39
|
-
keyMaterial
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
async function decryptData(encryptedData, keyMaterial) {
|
|
43
|
-
const ciphertext = toUint8Array(encryptedData.ciphertext);
|
|
44
|
-
const iv = toUint8Array(encryptedData.iv);
|
|
45
|
-
const authTag = toUint8Array(encryptedData.authTag);
|
|
46
|
-
const sealed = new Uint8Array(ciphertext.length + authTag.length);
|
|
47
|
-
sealed.set(ciphertext, 0);
|
|
48
|
-
sealed.set(authTag, ciphertext.length);
|
|
49
|
-
return aesGcmDecrypt(keyMaterial, sealed, iv);
|
|
50
|
-
}
|
|
51
|
-
function toUint8Array(data) {
|
|
52
|
-
if (data instanceof Uint8Array) return data;
|
|
53
|
-
if (Array.isArray(data)) return new Uint8Array(data);
|
|
54
|
-
return new Uint8Array(Object.values(data));
|
|
55
|
-
}
|
|
56
24
|
|
|
57
25
|
//#endregion
|
|
58
|
-
export { AES_KEY_LENGTH, GCM_NONCE_LENGTH, GCM_TAG_LENGTH, aesGcmDecrypt, aesGcmEncrypt
|
|
26
|
+
export { AES_KEY_LENGTH, GCM_NONCE_LENGTH, GCM_TAG_LENGTH, aesGcmDecrypt, aesGcmEncrypt };
|