@ic402/client 0.1.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.
package/dist/client.js ADDED
@@ -0,0 +1,309 @@
1
+ import { signVoucher } from './voucher.js';
2
+ /**
3
+ * ic402 TypeScript client SDK.
4
+ *
5
+ * Handles x402 charge payments and streaming sessions against
6
+ * ic402-enabled ICP canisters.
7
+ */
8
+ export class Ic402Client {
9
+ config;
10
+ totalSpent = 0n;
11
+ constructor(config) {
12
+ this.config = config;
13
+ }
14
+ /**
15
+ * Call a canister method, auto-handling 402 payment if needed.
16
+ *
17
+ * Flow: call method → if #paymentRequired → icrc2_approve → create sig → retry
18
+ */
19
+ async call(canisterId, method, args,
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ actorFactory) {
22
+ if (!actorFactory) {
23
+ throw new Error('actorFactory required: provide a function that creates an actor for the canister');
24
+ }
25
+ const actor = actorFactory(canisterId);
26
+ const result = await actor[method](...args);
27
+ // Check for payment required response
28
+ if (result && typeof result === 'object' && 'paymentRequired' in result) {
29
+ if (!this.config.autoPayment) {
30
+ throw new Error('Payment required but autoPayment is disabled');
31
+ }
32
+ const requirement = result.paymentRequired;
33
+ // Check budget limits
34
+ if (this.config.budget?.maxPerRequest &&
35
+ requirement.amount > this.config.budget.maxPerRequest) {
36
+ throw new Error(`Amount ${requirement.amount} exceeds maxPerRequest ${this.config.budget.maxPerRequest}`);
37
+ }
38
+ if (this.config.budget?.maxTotal &&
39
+ this.totalSpent + requirement.amount > this.config.budget.maxTotal) {
40
+ throw new Error('Total budget exceeded');
41
+ }
42
+ if (!this.config.ledger || !this.config.ledgerActorFactory) {
43
+ throw new Error('Auto-approval requires ledger and ledgerActorFactory in config');
44
+ }
45
+ // ICRC-2 approve: allow the target canister to spend the required amount
46
+ const ledgerActor = this.config.ledgerActorFactory(this.config.ledger);
47
+ const approveResult = await ledgerActor.icrc2_approve({
48
+ spender: { owner: canisterId, subaccount: [] },
49
+ amount: requirement.amount,
50
+ fee: [],
51
+ memo: [],
52
+ from_subaccount: [],
53
+ created_at_time: [],
54
+ expected_allowance: [],
55
+ expires_at: [],
56
+ });
57
+ if (approveResult && typeof approveResult === 'object' && 'Err' in approveResult) {
58
+ throw new Error(`ICRC-2 approve failed: ${JSON.stringify(approveResult.Err)}`);
59
+ }
60
+ this.totalSpent += requirement.amount;
61
+ // Construct PaymentSignature from the requirement's nonce and retry
62
+ const sig = {
63
+ scheme: 'exact',
64
+ network: this.config.network,
65
+ signature: requirement.nonce,
66
+ publicKey: [],
67
+ sender: '',
68
+ nonce: requirement.nonce,
69
+ authorization: [],
70
+ };
71
+ // Retry: replace the last arg (optional PaymentSignature) with our sig
72
+ const retryArgs = [...args];
73
+ retryArgs[retryArgs.length - 1] = [sig];
74
+ const retryResult = await actor[method](...retryArgs);
75
+ if (retryResult && typeof retryResult === 'object' && 'ok' in retryResult) {
76
+ return retryResult.ok;
77
+ }
78
+ return retryResult;
79
+ }
80
+ if (result && typeof result === 'object' && 'ok' in result) {
81
+ return result.ok;
82
+ }
83
+ return result;
84
+ }
85
+ /**
86
+ * Open a streaming session with escrow deposit.
87
+ *
88
+ * Flow: requestSession → calculate deposit → icrc2_approve → openSession → SessionHandle
89
+ */
90
+ async openSession(canisterId, config,
91
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
+ actorFactory, signer) {
93
+ if (!actorFactory) {
94
+ throw new Error('actorFactory required');
95
+ }
96
+ const actor = actorFactory(canisterId);
97
+ let intent = await actor.requestSession();
98
+ // For EVM sessions, override the intent's network, token, and recipient
99
+ if (config?.evmNetwork) {
100
+ intent = {
101
+ ...intent,
102
+ network: config.evmNetwork,
103
+ ...(config.evmToken ? { token: config.evmToken } : {}),
104
+ ...(config.evmRecipient ? { recipient: config.evmRecipient } : {}),
105
+ };
106
+ }
107
+ const maxDeposit = config?.maxDeposit ?? this.config.sessions?.maxDeposit ?? intent.suggestedDeposit;
108
+ const autoClose = config?.autoClose ?? this.config.sessions?.autoClose ?? true;
109
+ const idleTimeout = config?.idleTimeout ?? this.config.sessions?.idleTimeout;
110
+ // Check budget
111
+ if (this.config.budget?.maxSessionDeposit &&
112
+ maxDeposit > this.config.budget.maxSessionDeposit) {
113
+ throw new Error(`Deposit ${maxDeposit} exceeds maxSessionDeposit ${this.config.budget.maxSessionDeposit}`);
114
+ }
115
+ const isEvm = !!config?.evmTxHash;
116
+ const network = config?.evmNetwork ?? this.config.network;
117
+ // ICRC-2 approve deposit amount (ICP sessions only)
118
+ if (!isEvm && this.config.autoPayment && this.config.ledger && this.config.ledgerActorFactory) {
119
+ const ledgerActor = this.config.ledgerActorFactory(this.config.ledger);
120
+ const approveResult = await ledgerActor.icrc2_approve({
121
+ spender: { owner: canisterId, subaccount: [] },
122
+ amount: maxDeposit,
123
+ fee: [],
124
+ memo: [],
125
+ from_subaccount: [],
126
+ created_at_time: [],
127
+ expected_allowance: [],
128
+ expires_at: [],
129
+ });
130
+ if (approveResult && typeof approveResult === 'object' && 'Err' in approveResult) {
131
+ throw new Error(`ICRC-2 approve failed: ${JSON.stringify(approveResult.Err)}`);
132
+ }
133
+ }
134
+ const sessionConfig = {
135
+ maxDeposit,
136
+ autoClose,
137
+ idleTimeout: idleTimeout ? [idleTimeout] : [],
138
+ };
139
+ // Construct a payment signature.
140
+ // publicKey: Ed25519 public key for voucher verification (both ICP and EVM).
141
+ // signature: empty for ICP, EVM tx hash bytes for EVM.
142
+ // sender: empty for ICP (filled by identity), payer's EVM address for EVM.
143
+ let pubKey = new Uint8Array(32);
144
+ if (signer) {
145
+ pubKey = new Uint8Array(await signer.getPublicKey());
146
+ }
147
+ const sig = {
148
+ scheme: 'exact',
149
+ network,
150
+ signature: isEvm
151
+ ? Array.from(new TextEncoder().encode(config.evmTxHash))
152
+ : new Uint8Array(0),
153
+ publicKey: [Array.from(pubKey)],
154
+ sender: config?.evmSender ?? '',
155
+ nonce: new Uint8Array(32),
156
+ authorization: [],
157
+ };
158
+ const result = await actor.openSession(sessionConfig, sig);
159
+ if ('err' in result) {
160
+ throw new Error(`Failed to open session: ${result.err}`);
161
+ }
162
+ const state = result.ok;
163
+ let sequence = 0n;
164
+ let consumed = 0n;
165
+ const handle = {
166
+ id: state.id,
167
+ deposited: state.deposited,
168
+ get consumed() {
169
+ return consumed;
170
+ },
171
+ get remaining() {
172
+ return state.deposited - consumed;
173
+ },
174
+ async call(method, callArgs) {
175
+ // Calculate new cumulative amount (costPerCall from intent, or 1 unit)
176
+ // costPerCall is opt nat — Candid decodes as [bigint] or []
177
+ const rawCost = intent.costPerCall;
178
+ const cost = Array.isArray(rawCost) && rawCost.length > 0
179
+ ? BigInt(rawCost[0])
180
+ : typeof rawCost === 'bigint'
181
+ ? rawCost
182
+ : 1n;
183
+ consumed += cost;
184
+ sequence += 1n;
185
+ // Sign voucher
186
+ let signature = new Uint8Array(64);
187
+ if (signer) {
188
+ signature = new Uint8Array(await signVoucher(signer, state.id, consumed, sequence));
189
+ }
190
+ const voucher = {
191
+ sessionId: state.id,
192
+ cumulativeAmount: consumed,
193
+ sequence,
194
+ signature,
195
+ };
196
+ const callResult = await actor[method](voucher, ...callArgs);
197
+ if (callResult && typeof callResult === 'object' && 'ok' in callResult) {
198
+ return callResult.ok;
199
+ }
200
+ if (callResult && typeof callResult === 'object' && 'error' in callResult) {
201
+ throw new Error(callResult.error);
202
+ }
203
+ return callResult;
204
+ },
205
+ async callForContent(method, callArgs) {
206
+ const cost = intent.costPerCall ?? 1n;
207
+ consumed += cost;
208
+ sequence += 1n;
209
+ let sig = new Uint8Array(64);
210
+ if (signer) {
211
+ sig = new Uint8Array(await signVoucher(signer, state.id, consumed, sequence));
212
+ }
213
+ const v = {
214
+ sessionId: state.id,
215
+ cumulativeAmount: consumed,
216
+ sequence,
217
+ signature: sig,
218
+ };
219
+ const callResult = await actor[method](v, ...callArgs);
220
+ if (callResult && typeof callResult === 'object' && 'ok' in callResult) {
221
+ return callResult.ok;
222
+ }
223
+ if (callResult && typeof callResult === 'object' && 'error' in callResult) {
224
+ throw new Error(callResult.error);
225
+ }
226
+ return callResult;
227
+ },
228
+ async close() {
229
+ const closeResult = await actor.endSession(state.id);
230
+ if ('ok' in closeResult) {
231
+ return closeResult.ok;
232
+ }
233
+ throw new Error(`Failed to close session: ${JSON.stringify(closeResult)}`);
234
+ },
235
+ };
236
+ return handle;
237
+ }
238
+ /**
239
+ * Fetch content from a ContentDelivery response.
240
+ * Handles all delivery methods: inline, httpUrl, canisterQuery, assetCanister.
241
+ */
242
+ async fetchContent(delivery, options) {
243
+ const method = delivery.delivery;
244
+ if ('inline' in method) {
245
+ return method.inline;
246
+ }
247
+ if ('httpUrl' in method) {
248
+ // M-4: Validate URL scheme before fetching
249
+ const httpUrl = method.httpUrl;
250
+ if (!/^https?:\/\//i.test(httpUrl)) {
251
+ throw new Error(`Invalid httpUrl: must use http(s) scheme`);
252
+ }
253
+ const response = await fetch(httpUrl);
254
+ if (!response.ok)
255
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
256
+ return new Uint8Array(await response.arrayBuffer());
257
+ }
258
+ if ('assetCanister' in method) {
259
+ const { canisterId, path } = method.assetCanister;
260
+ // M-4: Validate canisterId format (ICP principal) and path (no traversal)
261
+ const cidStr = String(canisterId);
262
+ if (!/^[a-z0-9-]+$/.test(cidStr)) {
263
+ throw new Error(`Invalid canisterId format: ${cidStr}`);
264
+ }
265
+ if (typeof path !== 'string' || !path.startsWith('/') || path.includes('..')) {
266
+ throw new Error(`Invalid asset path: must start with / and not contain ..`);
267
+ }
268
+ const url = `https://${cidStr}.icp0.io${path}`;
269
+ const response = await fetch(url);
270
+ if (!response.ok)
271
+ throw new Error(`Asset canister ${response.status}: ${response.statusText}`);
272
+ return new Uint8Array(await response.arrayBuffer());
273
+ }
274
+ if ('canisterQuery' in method) {
275
+ const { method: queryMethod, chunkCount } = method.canisterQuery;
276
+ const cid = options?.canisterId;
277
+ if (!cid || !options?.actorFactory) {
278
+ throw new Error('canisterId and actorFactory required for canisterQuery delivery');
279
+ }
280
+ const actor = options.actorFactory(cid);
281
+ const chunks = [];
282
+ for (let i = 0n; i < chunkCount; i++) {
283
+ const chunk = await actor[queryMethod](delivery.grant, Number(i));
284
+ chunks.push(new Uint8Array(chunk));
285
+ }
286
+ const totalLength = chunks.reduce((acc, c) => acc + c.length, 0);
287
+ const result = new Uint8Array(totalLength);
288
+ let offset = 0;
289
+ for (const chunk of chunks) {
290
+ result.set(chunk, offset);
291
+ offset += chunk.length;
292
+ }
293
+ return result;
294
+ }
295
+ throw new Error('Unknown delivery method');
296
+ }
297
+ /**
298
+ * Discover agents via ERC-8004 registries.
299
+ *
300
+ * Stub: returns empty array. ERC-8004 IdentityRegistry and ReputationRegistry
301
+ * contracts are deployed but registries are sparse — no real agent data to
302
+ * query yet. When registries are populated, this will use viem to query
303
+ * on-chain agent cards filtered by chain, skills, and reputation.
304
+ */
305
+ async discoverAgents(_query) {
306
+ return [];
307
+ }
308
+ }
309
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAsB,MAAM,cAAc,CAAC;AA2D/D;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACd,MAAM,CAAoB;IAC1B,UAAU,GAAG,EAAE,CAAC;IAExB,YAAY,MAAyB;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAI,CACR,UAAkB,EAClB,MAAc,EACd,IAAe;IACf,8DAA8D;IAC9D,YAA0C;QAE1C,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;QACvC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,IA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AAC,KAAoB,CAAC,CAAC,CAAC;YACpD,CAAC;YACD,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YACjE,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;YAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;YACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;YACzB,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,cAAc,CAAC,MAKpB;QACC,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
@@ -0,0 +1,59 @@
1
+ /** EIP-712 domain for USDC contracts (Circle FiatTokenV2). */
2
+ export declare function usdcDomain(chainId: number, tokenAddress: string): {
3
+ name: "USD Coin";
4
+ version: "2";
5
+ chainId: number;
6
+ verifyingContract: `0x${string}`;
7
+ };
8
+ /** EIP-712 type definition for TransferWithAuthorization. */
9
+ export declare const TRANSFER_WITH_AUTHORIZATION_TYPES: {
10
+ readonly TransferWithAuthorization: readonly [{
11
+ readonly name: "from";
12
+ readonly type: "address";
13
+ }, {
14
+ readonly name: "to";
15
+ readonly type: "address";
16
+ }, {
17
+ readonly name: "value";
18
+ readonly type: "uint256";
19
+ }, {
20
+ readonly name: "validAfter";
21
+ readonly type: "uint256";
22
+ }, {
23
+ readonly name: "validBefore";
24
+ readonly type: "uint256";
25
+ }, {
26
+ readonly name: "nonce";
27
+ readonly type: "bytes32";
28
+ }];
29
+ };
30
+ /** Parameters for building a TransferWithAuthorization. */
31
+ export interface TransferAuthorizationParams {
32
+ from: string;
33
+ to: string;
34
+ value: bigint;
35
+ validAfter?: number;
36
+ validBefore?: number;
37
+ }
38
+ /** Generate a random bytes32 hex string for the EIP-3009 nonce.
39
+ * C-2: Requires Web Crypto API — no insecure Math.random() fallback. */
40
+ export declare function randomNonce(): string;
41
+ /** Build the EIP-712 message for TransferWithAuthorization. */
42
+ export declare function buildTransferAuthorizationMessage(params: TransferAuthorizationParams): {
43
+ from: `0x${string}`;
44
+ to: `0x${string}`;
45
+ value: bigint;
46
+ validAfter: bigint;
47
+ validBefore: bigint;
48
+ nonce: `0x${string}`;
49
+ };
50
+ /** Build the base64-encoded X-PAYMENT header for x402. */
51
+ export declare function buildX402PaymentHeader(network: string, signature: string, authorization: {
52
+ from: string;
53
+ to: string;
54
+ value: bigint;
55
+ validAfter: bigint;
56
+ validBefore: bigint;
57
+ nonce: string;
58
+ }): string;
59
+ //# sourceMappingURL=eip712.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eip712.d.ts","sourceRoot":"","sources":["../src/eip712.ts"],"names":[],"mappings":"AAMA,8DAA8D;AAC9D,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;;;;uBAKzB,KAAK,MAAM,EAAE;EAEnD;AAED,6DAA6D;AAC7D,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;CASpC,CAAC;AAEX,2DAA2D;AAC3D,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;yEACyE;AACzE,wBAAgB,WAAW,IAAI,MAAM,CAepC;AAED,+DAA+D;AAC/D,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,2BAA2B;UAM5D,KAAK,MAAM,EAAE;QACjB,KAAK,MAAM,EAAE;;;;WAId,KAAK,MAAM,EAAE;EAEhC;AAED,0DAA0D;AAC1D,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf,GACA,MAAM,CAmBR"}
package/dist/eip712.js ADDED
@@ -0,0 +1,74 @@
1
+ /// EIP-712 typed data construction for TransferWithAuthorization.
2
+ ///
3
+ /// Builds the typed data structure that standard x402 clients sign
4
+ /// for EIP-3009 USDC transfers. Works with any EIP-712 signer
5
+ /// (viem, ethers, MetaMask, etc.).
6
+ /** EIP-712 domain for USDC contracts (Circle FiatTokenV2). */
7
+ export function usdcDomain(chainId, tokenAddress) {
8
+ return {
9
+ name: 'USD Coin',
10
+ version: '2',
11
+ chainId,
12
+ verifyingContract: tokenAddress,
13
+ };
14
+ }
15
+ /** EIP-712 type definition for TransferWithAuthorization. */
16
+ export const TRANSFER_WITH_AUTHORIZATION_TYPES = {
17
+ TransferWithAuthorization: [
18
+ { name: 'from', type: 'address' },
19
+ { name: 'to', type: 'address' },
20
+ { name: 'value', type: 'uint256' },
21
+ { name: 'validAfter', type: 'uint256' },
22
+ { name: 'validBefore', type: 'uint256' },
23
+ { name: 'nonce', type: 'bytes32' },
24
+ ],
25
+ };
26
+ /** Generate a random bytes32 hex string for the EIP-3009 nonce.
27
+ * C-2: Requires Web Crypto API — no insecure Math.random() fallback. */
28
+ export function randomNonce() {
29
+ if (typeof globalThis.crypto === 'undefined' || !globalThis.crypto.getRandomValues) {
30
+ throw new Error('ic402: Web Crypto API required for secure nonce generation. ' +
31
+ 'Ensure globalThis.crypto.getRandomValues is available (Node.js >= 19, modern browsers, or polyfill).');
32
+ }
33
+ const bytes = new Uint8Array(32);
34
+ globalThis.crypto.getRandomValues(bytes);
35
+ return ('0x' +
36
+ Array.from(bytes)
37
+ .map((b) => b.toString(16).padStart(2, '0'))
38
+ .join(''));
39
+ }
40
+ /** Build the EIP-712 message for TransferWithAuthorization. */
41
+ export function buildTransferAuthorizationMessage(params) {
42
+ const nonce = randomNonce();
43
+ const validAfter = params.validAfter ?? 0;
44
+ const validBefore = params.validBefore ?? Math.floor(Date.now() / 1000) + 300;
45
+ return {
46
+ from: params.from,
47
+ to: params.to,
48
+ value: params.value,
49
+ validAfter: BigInt(validAfter),
50
+ validBefore: BigInt(validBefore),
51
+ nonce: nonce,
52
+ };
53
+ }
54
+ /** Build the base64-encoded X-PAYMENT header for x402. */
55
+ export function buildX402PaymentHeader(network, signature, authorization) {
56
+ const payload = {
57
+ x402Version: 1,
58
+ scheme: 'exact',
59
+ network,
60
+ payload: {
61
+ signature,
62
+ authorization: {
63
+ from: authorization.from,
64
+ to: authorization.to,
65
+ value: authorization.value.toString(),
66
+ validAfter: authorization.validAfter.toString(),
67
+ validBefore: authorization.validBefore.toString(),
68
+ nonce: authorization.nonce,
69
+ },
70
+ },
71
+ };
72
+ return btoa(JSON.stringify(payload));
73
+ }
74
+ //# sourceMappingURL=eip712.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eip712.js","sourceRoot":"","sources":["../src/eip712.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,GAAG;AACH,mEAAmE;AACnE,8DAA8D;AAC9D,mCAAmC;AAEnC,8DAA8D;AAC9D,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,YAAoB;IAC9D,OAAO;QACL,IAAI,EAAE,UAAmB;QACzB,OAAO,EAAE,GAAY;QACrB,OAAO;QACP,iBAAiB,EAAE,YAA6B;KACjD,CAAC;AACJ,CAAC;AAED,6DAA6D;AAC7D,MAAM,CAAC,MAAM,iCAAiC,GAAG;IAC/C,yBAAyB,EAAE;QACzB,EAAE,IAAI,EAAE,M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C;IAE9E,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAqB;QAClC,EAAE,EAAE,MAAM,CAAC,EAAmB;QAC9B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC;QAC9B,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC;QAChC,KAAK,EAAE,KAAsB;KAC9B,CAAC;AACJ,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,sBAAsB,CACpC,OAAe,EACf,SAAiB,EACjB,aAOC;IAED,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,CAAC;QACd,MAAM,EAAE,OAAO;QACf,OAAO;QACP,OAAO,EAAE;YACP,SAAS;YACT,aAAa,EAAE;gBACb,IAAI,EAAE,aAAa,CAAC,IAAI;gBACxB,EAAE,EAAE,aAAa,CAAC,EAAE;gBACpB,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE;gBACrC,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE;gBAC/C,WAAW,EAAE,aAAa,CAAC,WAAW,CAAC,QAAQ,EAAE;gBACjD,KAAK,EAAE,aAAa,CAAC,KAAK;aAC3B;SACF;KACF,CAAC;IAEF,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;AACvC,CAAC"}
package/dist/idl.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ import { IDL } from '@icp-sdk/core/candid';
2
+ declare const PaymentRequirement: IDL.RecordClass;
3
+ declare const PaymentSignature: IDL.RecordClass;
4
+ declare const PaymentReceipt: IDL.RecordClass;
5
+ declare const PaymentResult: IDL.VariantClass;
6
+ declare const SessionIntent: IDL.RecordClass;
7
+ declare const SessionState: IDL.RecordClass;
8
+ declare const SessionConfig: IDL.RecordClass;
9
+ declare const Voucher: IDL.RecordClass;
10
+ declare const SpendingPolicy: IDL.RecordClass;
11
+ declare const ContentRef: IDL.RecordClass;
12
+ declare const AccessGrant: IDL.RecordClass;
13
+ declare const AccessGrantResult: IDL.VariantClass;
14
+ declare const DeliveryMethod: IDL.VariantClass;
15
+ declare const ContentDelivery: IDL.RecordClass;
16
+ declare const GetContentResult: IDL.VariantClass;
17
+ declare const ServiceEntry: IDL.RecordClass;
18
+ declare const AgentCard: IDL.RecordClass;
19
+ declare const ContentEntry: IDL.RecordClass;
20
+ declare const ContentStoreResult: IDL.VariantClass;
21
+ export declare const exampleIdlFactory: () => IDL.ServiceClass<string, {
22
+ search: IDL.FuncClass<[IDL.TextClass, IDL.OptClass<Record<string, any>>], [IDL.VariantClass]>;
23
+ requestSession: IDL.FuncClass<[], [IDL.RecordClass]>;
24
+ openSession: IDL.FuncClass<[IDL.RecordClass, IDL.RecordClass], [IDL.VariantClass]>;
25
+ sessionQuery: IDL.FuncClass<[IDL.RecordClass, IDL.TextClass], [IDL.VariantClass]>;
26
+ endSession: IDL.FuncClass<[IDL.TextClass], [IDL.VariantClass]>;
27
+ uploadContent: IDL.FuncClass<[IDL.TextClass, IDL.TextClass, IDL.VecClass<number | bigint>], [IDL.VariantClass]>;
28
+ uploadContentInit: IDL.FuncClass<[IDL.TextClass, IDL.TextClass, IDL.NatClass, IDL.NatClass], [IDL.VariantClass]>;
29
+ uploadContentChunk: IDL.FuncClass<[IDL.TextClass, IDL.NatClass, IDL.VecClass<number | bigint>], [IDL.VariantClass]>;
30
+ deleteContent: IDL.FuncClass<[IDL.TextClass], [IDL.VariantClass]>;
31
+ listContent: IDL.FuncClass<[], [IDL.VecClass<Record<string, any>>]>;
32
+ getContent: IDL.FuncClass<[IDL.TextClass, IDL.OptClass<Record<string, any>>], [IDL.VariantClass]>;
33
+ getChunk: IDL.FuncClass<[IDL.RecordClass, IDL.NatClass], [IDL.OptClass<(number | bigint)[]>]>;
34
+ getAssetContent: IDL.FuncClass<[IDL.TextClass, IDL.OptClass<Record<string, any>>], [IDL.VariantClass]>;
35
+ getExternalContent: IDL.FuncClass<[IDL.TextClass, IDL.OptClass<Record<string, any>>], [IDL.VariantClass]>;
36
+ getAgentCard: IDL.FuncClass<[], [IDL.RecordClass]>;
37
+ getAgentId: IDL.FuncClass<[], [IDL.OptClass<number | bigint>]>;
38
+ getEvmPublicKey: IDL.FuncClass<[], [IDL.VecClass<number | bigint>]>;
39
+ getEvmAddress: IDL.FuncClass<[], [IDL.TextClass]>;
40
+ registerAgent: IDL.FuncClass<[], [IDL.VariantClass]>;
41
+ fetchX402: IDL.FuncClass<[IDL.TextClass], [IDL.VariantClass]>;
42
+ fetchX402Post: IDL.FuncClass<[IDL.TextClass, IDL.TextClass, IDL.TextClass], [IDL.VariantClass]>;
43
+ verifyGrant: IDL.FuncClass<[IDL.RecordClass], [IDL.VariantClass]>;
44
+ setPolicy: IDL.FuncClass<[IDL.RecordClass], []>;
45
+ forceCloseSession: IDL.FuncClass<[IDL.TextClass], [IDL.VariantClass]>;
46
+ }>;
47
+ export { PaymentRequirement, PaymentSignature, PaymentReceipt, PaymentResult, SessionIntent, SessionState, SessionConfig, Voucher, SpendingPolicy, ContentRef, AccessGrant, AccessGrantResult, DeliveryMethod, ContentDelivery, GetContentResult, ContentEntry, ContentStoreResult, ServiceEntry, AgentCard, };
48
+ //# sourceMappingURL=idl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idl.d.ts","sourceRoot":"","sources":["../src/idl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAE3C,QAAA,MAAM,kBAAkB,iBAUtB,CAAC;AAcH,QAAA,MAAM,gBAAgB,iBAQpB,CAAC;AAEH,QAAA,MAAM,cAAc,iBAWlB,CAAC;AAEH,QAAA,MAAM,aAAa,kBAWjB,CAAC;AAEH,QAAA,MAAM,aAAa,iBASjB,CAAC;AASH,QAAA,MAAM,YAAY,iBAUhB,CAAC;AAEH,QAAA,MAAM,aAAa,iBAIjB,CAAC;AAEH,QAAA,MAAM,OAAO,iBAKX,CAAC;AAEH,Q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