uvd-x402-sdk 2.108.0 → 2.109.0

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.
@@ -19,7 +19,7 @@ interface PaymentIdParams extends EscrowMsgParams {
19
19
  }
20
20
  interface NearLocalSigner {
21
21
  readonly publicKey: Uint8Array;
22
- /** Sign the NEP-366 SHA-256 digest directly, without a NEP-413 envelope. */
22
+ /** Sign the supplied SHA-256 digest directly. The calling helper supplies its domain prefix. */
23
23
  sign(digest: Uint8Array): Uint8Array | Promise<Uint8Array>;
24
24
  }
25
25
  interface NearEscrowDelegateOptions {
@@ -95,6 +95,154 @@ declare const withdrawFor: (o: NearEscrowDelegateOptions, account: string) => Pr
95
95
  interface AuthorizeFromBudget {
96
96
  authorizeFromBudget(request: unknown): Promise<NearEscrowPayment>;
97
97
  }
98
+ /** Local-key exact NEP-366 payment; uses the escrow serializer and raw digest signer. */
99
+ interface NearExactDelegateOptions extends Omit<NearEscrowDelegateOptions, 'escrowContract'> {
100
+ token: string;
101
+ payTo: string;
102
+ amount: NearUnsigned;
103
+ }
104
+ interface NearExactPayment extends Omit<NearEscrowPayment, 'scheme'> {
105
+ scheme: 'exact';
106
+ }
107
+ declare function signExactNearDelegate(options: NearExactDelegateOptions): Promise<NearExactPayment>;
108
+
109
+ interface Nep413Message {
110
+ message: string;
111
+ nonce: Uint8Array;
112
+ recipient: string;
113
+ callbackUrl?: string;
114
+ }
115
+ interface SignNep413Options extends Nep413Message {
116
+ signer: NearLocalSigner;
117
+ accountId: string;
118
+ }
119
+ interface Nep413SignedMessage {
120
+ accountId: string;
121
+ publicKey: string;
122
+ signature: string;
123
+ }
124
+ /** Prefix 2^31+413 followed by message, fixed nonce, recipient and Option<String> callback. */
125
+ declare function nep413Preimage(options: Nep413Message): Uint8Array;
126
+ declare function signNep413(options: SignNep413Options): Promise<Nep413SignedMessage>;
127
+
128
+ /** Payer-funded NEP-145 calls. These are unsigned normal transactions, never facilitator delegates. */
129
+
130
+ interface NearStorageTransaction {
131
+ signerId: string;
132
+ receiverId: string;
133
+ actions: [
134
+ {
135
+ type: 'FunctionCall';
136
+ params: {
137
+ methodName: 'storage_deposit';
138
+ args: {
139
+ account_id: string;
140
+ registration_only: boolean;
141
+ };
142
+ gas: string;
143
+ deposit: string;
144
+ };
145
+ }
146
+ ];
147
+ }
148
+ interface NearStorageOptions {
149
+ network: NearEscrowNetwork;
150
+ /** Account that signs the normal transaction and pays its deposit and gas. */
151
+ payerId: string;
152
+ /** Account to register or fund; defaults to payerId. */
153
+ accountId?: string;
154
+ /** YoctoNEAR, not NEAR. Query storage_balance_bounds for the live contract minimum. */
155
+ deposit?: NearUnsigned;
156
+ }
157
+ /** Explicit trusted deployment configuration; this unsigned builder does not select an account parent. */
158
+ interface ArrasStorageOptions extends NearStorageOptions {
159
+ escrowContract: string;
160
+ }
161
+ declare const NEAR_ARRAS_STORAGE_DEPOSIT = "50000000000000000000000";
162
+ declare const NEAR_USDC_STORAGE_DEPOSIT = "1250000000000000000000";
163
+ /** Keep surplus available for payment storage; registration_only must be false for Arras. */
164
+ declare function buildArrasStorageDeposit(options: ArrasStorageOptions): NearStorageTransaction;
165
+ /** Register in native USDC; refund any surplus rather than topping up an FT registration. */
166
+ declare function buildUsdcStorageDeposit(options: NearStorageOptions): NearStorageTransaction;
167
+
168
+ interface ArrasAuthorizedData {
169
+ payment_id: string;
170
+ operator_id: string;
171
+ token: string;
172
+ payer: string;
173
+ receiver: string;
174
+ amount: string;
175
+ fee_bps: number;
176
+ fee_recipient: string;
177
+ terms_hash: string;
178
+ }
179
+ interface ArrasReleasedData {
180
+ payment_id: string;
181
+ amount: string;
182
+ net: string;
183
+ fee: string;
184
+ }
185
+ interface ArrasPaymentAmountData {
186
+ payment_id: string;
187
+ amount: string;
188
+ }
189
+ interface ArrasWithdrawnData {
190
+ account: string;
191
+ token: string;
192
+ amount: string;
193
+ ok: boolean;
194
+ }
195
+ interface ArrasCompactedData {
196
+ payment_id: string;
197
+ }
198
+ interface ArrasOperatorData {
199
+ operator_id: string;
200
+ owner?: string;
201
+ capturers?: string[];
202
+ fee_bps?: number;
203
+ fee_recipient?: string;
204
+ min_amount?: string;
205
+ tope_tvl_operador?: string;
206
+ tope_tvl_por_payer?: string;
207
+ sponsor_max_por_payer?: string;
208
+ }
209
+ interface ArrasCapsSetData {
210
+ by: string;
211
+ tope_por_pago: string;
212
+ tope_tvl_global: string;
213
+ }
214
+ interface ArrasPauseData {
215
+ by: string;
216
+ paused: boolean;
217
+ at: string;
218
+ }
219
+ interface ArrasEventData {
220
+ authorized: ArrasAuthorizedData;
221
+ released: ArrasReleasedData;
222
+ refunded: ArrasPaymentAmountData;
223
+ reclaimed: ArrasPaymentAmountData;
224
+ withdrawn: ArrasWithdrawnData;
225
+ compacted: ArrasCompactedData;
226
+ operator_registered: ArrasOperatorData;
227
+ operator_updated: ArrasOperatorData;
228
+ caps_set: ArrasCapsSetData;
229
+ paused: ArrasPauseData;
230
+ unpaused: ArrasPauseData;
231
+ }
232
+ type ArrasEvent = {
233
+ [K in keyof ArrasEventData]: {
234
+ standard: 'arras';
235
+ version: '1.0.0';
236
+ event: K;
237
+ data: ArrasEventData[K][];
238
+ };
239
+ }[keyof ArrasEventData];
240
+ /**
241
+ * Pass flattened receipt outcome logs. Foreign logs, malformed envelopes/data and unknown
242
+ * standards, versions or events are skipped. Preserve each batch and decimal integer bytes.
243
+ * Logs alone do not authenticate the emitter: the caller must check the receipt executor/status.
244
+ */
245
+ declare function parseArrasEvents(logs: readonly unknown[]): ArrasEvent[];
98
246
 
99
247
  /**
100
248
  * uvd-x402-sdk - NEAR Provider
@@ -234,4 +382,4 @@ declare class NEARProvider implements WalletAdapter {
234
382
  private base58Encode;
235
383
  }
236
384
 
237
- export { type AuthorizeFromBudget, type EscrowAuthorizationOptions, type EscrowMsgParams, NEARProvider, NEAR_ESCROW_CONTRACTS, NEAR_ESCROW_MAX_GAS, NEAR_ESCROW_MIN_GAS, NEAR_ESCROW_TOKENS, type NearEscrowDelegate, type NearEscrowDelegateOptions, type NearEscrowFunctionCall, type NearEscrowLifecycleMethod, type NearEscrowNetwork, type NearEscrowPayment, type NearLocalSigner, type NearUnsigned, type PaymentIdParams, type WalletSelectorOptions, buildEscrowAuthorizationDelegate, buildEscrowMsg, computePaymentId, createNearLocalSigner, NEARProvider as default, paymentIdPreimage, reclaim, refund, release, signEscrowAuthorization, signEscrowLifecycle, validateEscrowAuthorizationDelegate, withdraw, withdrawFor };
385
+ export { type ArrasAuthorizedData, type ArrasCapsSetData, type ArrasCompactedData, type ArrasEvent, type ArrasEventData, type ArrasOperatorData, type ArrasPauseData, type ArrasPaymentAmountData, type ArrasReleasedData, type ArrasStorageOptions, type ArrasWithdrawnData, type AuthorizeFromBudget, type EscrowAuthorizationOptions, type EscrowMsgParams, NEARProvider, NEAR_ARRAS_STORAGE_DEPOSIT, NEAR_ESCROW_CONTRACTS, NEAR_ESCROW_MAX_GAS, NEAR_ESCROW_MIN_GAS, NEAR_ESCROW_TOKENS, NEAR_USDC_STORAGE_DEPOSIT, type NearEscrowDelegate, type NearEscrowDelegateOptions, type NearEscrowFunctionCall, type NearEscrowLifecycleMethod, type NearEscrowNetwork, type NearEscrowPayment, type NearExactDelegateOptions, type NearExactPayment, type NearLocalSigner, type NearStorageOptions, type NearStorageTransaction, type NearUnsigned, type Nep413Message, type Nep413SignedMessage, type PaymentIdParams, type SignNep413Options, type WalletSelectorOptions, buildArrasStorageDeposit, buildEscrowAuthorizationDelegate, buildEscrowMsg, buildUsdcStorageDeposit, computePaymentId, createNearLocalSigner, NEARProvider as default, nep413Preimage, parseArrasEvents, paymentIdPreimage, reclaim, refund, release, signEscrowAuthorization, signEscrowLifecycle, signExactNearDelegate, signNep413, validateEscrowAuthorizationDelegate, withdraw, withdrawFor };
@@ -19,7 +19,7 @@ interface PaymentIdParams extends EscrowMsgParams {
19
19
  }
20
20
  interface NearLocalSigner {
21
21
  readonly publicKey: Uint8Array;
22
- /** Sign the NEP-366 SHA-256 digest directly, without a NEP-413 envelope. */
22
+ /** Sign the supplied SHA-256 digest directly. The calling helper supplies its domain prefix. */
23
23
  sign(digest: Uint8Array): Uint8Array | Promise<Uint8Array>;
24
24
  }
25
25
  interface NearEscrowDelegateOptions {
@@ -95,6 +95,154 @@ declare const withdrawFor: (o: NearEscrowDelegateOptions, account: string) => Pr
95
95
  interface AuthorizeFromBudget {
96
96
  authorizeFromBudget(request: unknown): Promise<NearEscrowPayment>;
97
97
  }
98
+ /** Local-key exact NEP-366 payment; uses the escrow serializer and raw digest signer. */
99
+ interface NearExactDelegateOptions extends Omit<NearEscrowDelegateOptions, 'escrowContract'> {
100
+ token: string;
101
+ payTo: string;
102
+ amount: NearUnsigned;
103
+ }
104
+ interface NearExactPayment extends Omit<NearEscrowPayment, 'scheme'> {
105
+ scheme: 'exact';
106
+ }
107
+ declare function signExactNearDelegate(options: NearExactDelegateOptions): Promise<NearExactPayment>;
108
+
109
+ interface Nep413Message {
110
+ message: string;
111
+ nonce: Uint8Array;
112
+ recipient: string;
113
+ callbackUrl?: string;
114
+ }
115
+ interface SignNep413Options extends Nep413Message {
116
+ signer: NearLocalSigner;
117
+ accountId: string;
118
+ }
119
+ interface Nep413SignedMessage {
120
+ accountId: string;
121
+ publicKey: string;
122
+ signature: string;
123
+ }
124
+ /** Prefix 2^31+413 followed by message, fixed nonce, recipient and Option<String> callback. */
125
+ declare function nep413Preimage(options: Nep413Message): Uint8Array;
126
+ declare function signNep413(options: SignNep413Options): Promise<Nep413SignedMessage>;
127
+
128
+ /** Payer-funded NEP-145 calls. These are unsigned normal transactions, never facilitator delegates. */
129
+
130
+ interface NearStorageTransaction {
131
+ signerId: string;
132
+ receiverId: string;
133
+ actions: [
134
+ {
135
+ type: 'FunctionCall';
136
+ params: {
137
+ methodName: 'storage_deposit';
138
+ args: {
139
+ account_id: string;
140
+ registration_only: boolean;
141
+ };
142
+ gas: string;
143
+ deposit: string;
144
+ };
145
+ }
146
+ ];
147
+ }
148
+ interface NearStorageOptions {
149
+ network: NearEscrowNetwork;
150
+ /** Account that signs the normal transaction and pays its deposit and gas. */
151
+ payerId: string;
152
+ /** Account to register or fund; defaults to payerId. */
153
+ accountId?: string;
154
+ /** YoctoNEAR, not NEAR. Query storage_balance_bounds for the live contract minimum. */
155
+ deposit?: NearUnsigned;
156
+ }
157
+ /** Explicit trusted deployment configuration; this unsigned builder does not select an account parent. */
158
+ interface ArrasStorageOptions extends NearStorageOptions {
159
+ escrowContract: string;
160
+ }
161
+ declare const NEAR_ARRAS_STORAGE_DEPOSIT = "50000000000000000000000";
162
+ declare const NEAR_USDC_STORAGE_DEPOSIT = "1250000000000000000000";
163
+ /** Keep surplus available for payment storage; registration_only must be false for Arras. */
164
+ declare function buildArrasStorageDeposit(options: ArrasStorageOptions): NearStorageTransaction;
165
+ /** Register in native USDC; refund any surplus rather than topping up an FT registration. */
166
+ declare function buildUsdcStorageDeposit(options: NearStorageOptions): NearStorageTransaction;
167
+
168
+ interface ArrasAuthorizedData {
169
+ payment_id: string;
170
+ operator_id: string;
171
+ token: string;
172
+ payer: string;
173
+ receiver: string;
174
+ amount: string;
175
+ fee_bps: number;
176
+ fee_recipient: string;
177
+ terms_hash: string;
178
+ }
179
+ interface ArrasReleasedData {
180
+ payment_id: string;
181
+ amount: string;
182
+ net: string;
183
+ fee: string;
184
+ }
185
+ interface ArrasPaymentAmountData {
186
+ payment_id: string;
187
+ amount: string;
188
+ }
189
+ interface ArrasWithdrawnData {
190
+ account: string;
191
+ token: string;
192
+ amount: string;
193
+ ok: boolean;
194
+ }
195
+ interface ArrasCompactedData {
196
+ payment_id: string;
197
+ }
198
+ interface ArrasOperatorData {
199
+ operator_id: string;
200
+ owner?: string;
201
+ capturers?: string[];
202
+ fee_bps?: number;
203
+ fee_recipient?: string;
204
+ min_amount?: string;
205
+ tope_tvl_operador?: string;
206
+ tope_tvl_por_payer?: string;
207
+ sponsor_max_por_payer?: string;
208
+ }
209
+ interface ArrasCapsSetData {
210
+ by: string;
211
+ tope_por_pago: string;
212
+ tope_tvl_global: string;
213
+ }
214
+ interface ArrasPauseData {
215
+ by: string;
216
+ paused: boolean;
217
+ at: string;
218
+ }
219
+ interface ArrasEventData {
220
+ authorized: ArrasAuthorizedData;
221
+ released: ArrasReleasedData;
222
+ refunded: ArrasPaymentAmountData;
223
+ reclaimed: ArrasPaymentAmountData;
224
+ withdrawn: ArrasWithdrawnData;
225
+ compacted: ArrasCompactedData;
226
+ operator_registered: ArrasOperatorData;
227
+ operator_updated: ArrasOperatorData;
228
+ caps_set: ArrasCapsSetData;
229
+ paused: ArrasPauseData;
230
+ unpaused: ArrasPauseData;
231
+ }
232
+ type ArrasEvent = {
233
+ [K in keyof ArrasEventData]: {
234
+ standard: 'arras';
235
+ version: '1.0.0';
236
+ event: K;
237
+ data: ArrasEventData[K][];
238
+ };
239
+ }[keyof ArrasEventData];
240
+ /**
241
+ * Pass flattened receipt outcome logs. Foreign logs, malformed envelopes/data and unknown
242
+ * standards, versions or events are skipped. Preserve each batch and decimal integer bytes.
243
+ * Logs alone do not authenticate the emitter: the caller must check the receipt executor/status.
244
+ */
245
+ declare function parseArrasEvents(logs: readonly unknown[]): ArrasEvent[];
98
246
 
99
247
  /**
100
248
  * uvd-x402-sdk - NEAR Provider
@@ -234,4 +382,4 @@ declare class NEARProvider implements WalletAdapter {
234
382
  private base58Encode;
235
383
  }
236
384
 
237
- export { type AuthorizeFromBudget, type EscrowAuthorizationOptions, type EscrowMsgParams, NEARProvider, NEAR_ESCROW_CONTRACTS, NEAR_ESCROW_MAX_GAS, NEAR_ESCROW_MIN_GAS, NEAR_ESCROW_TOKENS, type NearEscrowDelegate, type NearEscrowDelegateOptions, type NearEscrowFunctionCall, type NearEscrowLifecycleMethod, type NearEscrowNetwork, type NearEscrowPayment, type NearLocalSigner, type NearUnsigned, type PaymentIdParams, type WalletSelectorOptions, buildEscrowAuthorizationDelegate, buildEscrowMsg, computePaymentId, createNearLocalSigner, NEARProvider as default, paymentIdPreimage, reclaim, refund, release, signEscrowAuthorization, signEscrowLifecycle, validateEscrowAuthorizationDelegate, withdraw, withdrawFor };
385
+ export { type ArrasAuthorizedData, type ArrasCapsSetData, type ArrasCompactedData, type ArrasEvent, type ArrasEventData, type ArrasOperatorData, type ArrasPauseData, type ArrasPaymentAmountData, type ArrasReleasedData, type ArrasStorageOptions, type ArrasWithdrawnData, type AuthorizeFromBudget, type EscrowAuthorizationOptions, type EscrowMsgParams, NEARProvider, NEAR_ARRAS_STORAGE_DEPOSIT, NEAR_ESCROW_CONTRACTS, NEAR_ESCROW_MAX_GAS, NEAR_ESCROW_MIN_GAS, NEAR_ESCROW_TOKENS, NEAR_USDC_STORAGE_DEPOSIT, type NearEscrowDelegate, type NearEscrowDelegateOptions, type NearEscrowFunctionCall, type NearEscrowLifecycleMethod, type NearEscrowNetwork, type NearEscrowPayment, type NearExactDelegateOptions, type NearExactPayment, type NearLocalSigner, type NearStorageOptions, type NearStorageTransaction, type NearUnsigned, type Nep413Message, type Nep413SignedMessage, type PaymentIdParams, type SignNep413Options, type WalletSelectorOptions, buildArrasStorageDeposit, buildEscrowAuthorizationDelegate, buildEscrowMsg, buildUsdcStorageDeposit, computePaymentId, createNearLocalSigner, NEARProvider as default, nep413Preimage, parseArrasEvents, paymentIdPreimage, reclaim, refund, release, signEscrowAuthorization, signEscrowLifecycle, signExactNearDelegate, signNep413, validateEscrowAuthorizationDelegate, withdraw, withdrawFor };
@@ -1300,17 +1300,8 @@ function chainToCAIP2(chainName) {
1300
1300
  }
1301
1301
  return chainName;
1302
1302
  }
1303
- var NEAR_ESCROW_MIN_GAS = 38000000000000n;
1304
- var NEAR_ESCROW_MAX_GAS = 100000000000000n;
1305
- var NEAR_ESCROW_TOKENS = Object.freeze({
1306
- "near:mainnet": "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
1307
- "near:testnet": "3e2210e1184b45b64c8a434c0a7e7b23cc04ea7eb7a6c3c32520d03d4afcb8af"
1308
- });
1309
- var NEAR_ESCROW_CONTRACTS = Object.freeze({
1310
- "near:testnet": Object.freeze(["arras-v1b-1101.testnet"]),
1311
- "near:mainnet": Object.freeze([])
1312
- });
1313
- var NONCE_RANGE_MULTIPLIER = 1000000n;
1303
+
1304
+ // src/providers/near/encoding.ts
1314
1305
  function fullMatch(pattern, value) {
1315
1306
  return pattern.exec(value)?.[0] === value;
1316
1307
  }
@@ -1325,12 +1316,6 @@ function uint(value, bits, name) {
1325
1316
  function account(value, name) {
1326
1317
  if (typeof value !== "string" || value.length < 2 || value.length > 64 || !fullMatch(/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/, value)) throw new Error(`${name}: invalid NEAR account`);
1327
1318
  }
1328
- function hex(value, size, name) {
1329
- if (typeof value !== "string" || value.length !== size * 2 || !fullMatch(/^[0-9a-f]+$/, value)) {
1330
- throw new Error(`${name}: expected ${size} bytes of lowercase hex without 0x`);
1331
- }
1332
- return Uint8Array.from(value.match(/../g), (v) => parseInt(v, 16));
1333
- }
1334
1319
  function concat(...parts) {
1335
1320
  const out = new Uint8Array(parts.reduce((sum, p) => sum + p.length, 0));
1336
1321
  let at = 0;
@@ -1344,6 +1329,10 @@ function le(n, size) {
1344
1329
  return Uint8Array.from({ length: size }, (_, i) => Number(n >> BigInt(i * 8) & 255n));
1345
1330
  }
1346
1331
  function str(s) {
1332
+ for (const c of s) {
1333
+ const point = c.codePointAt(0);
1334
+ if (point >= 55296 && point <= 57343) throw new Error("Expected valid Unicode scalar values");
1335
+ }
1347
1336
  const bytes = new TextEncoder().encode(s);
1348
1337
  return concat(le(BigInt(bytes.length), 4), bytes);
1349
1338
  }
@@ -1364,6 +1353,25 @@ function unbase58(value) {
1364
1353
  const zeros = value.match(/^1*/u)[0].length;
1365
1354
  return concat(new Uint8Array(zeros), Uint8Array.from(bytes.reverse()));
1366
1355
  }
1356
+
1357
+ // src/providers/near/escrow.ts
1358
+ var NEAR_ESCROW_MIN_GAS = 38000000000000n;
1359
+ var NEAR_ESCROW_MAX_GAS = 100000000000000n;
1360
+ var NEAR_ESCROW_TOKENS = Object.freeze({
1361
+ "near:mainnet": "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
1362
+ "near:testnet": "3e2210e1184b45b64c8a434c0a7e7b23cc04ea7eb7a6c3c32520d03d4afcb8af"
1363
+ });
1364
+ var NEAR_ESCROW_CONTRACTS = Object.freeze({
1365
+ "near:testnet": Object.freeze(["arras-v1b-1101.testnet"]),
1366
+ "near:mainnet": Object.freeze([])
1367
+ });
1368
+ var NONCE_RANGE_MULTIPLIER = 1000000n;
1369
+ function hex(value, size, name) {
1370
+ if (typeof value !== "string" || value.length !== size * 2 || !fullMatch(/^[0-9a-f]+$/, value)) {
1371
+ throw new Error(`${name}: expected ${size} bytes of lowercase hex without 0x`);
1372
+ }
1373
+ return Uint8Array.from(value.match(/../g), (v) => parseInt(v, 16));
1374
+ }
1367
1375
  function msgValues(p) {
1368
1376
  if (typeof p.operator_id !== "string" || !fullMatch(/^[a-z0-9_-]{1,32}$/, p.operator_id)) {
1369
1377
  throw new Error("operator_id: expected [a-z0-9_-]{1,32}");
@@ -1373,8 +1381,8 @@ function msgValues(p) {
1373
1381
  const reclaim2 = uint(p.reclaim_after, 64, "reclaim_after");
1374
1382
  if (release2 >= reclaim2) throw new Error("release_deadline must precede reclaim_after");
1375
1383
  if (typeof p.fee_bps_max !== "number") throw new Error("fee_bps_max: expected a number");
1376
- const fee = uint(p.fee_bps_max, 16, "fee_bps_max");
1377
- return { release: release2, reclaim: reclaim2, fee, terms: hex(p.terms_hash, 32, "terms_hash"), salt: hex(p.salt, 16, "salt") };
1384
+ const fee2 = uint(p.fee_bps_max, 16, "fee_bps_max");
1385
+ return { release: release2, reclaim: reclaim2, fee: fee2, terms: hex(p.terms_hash, 32, "terms_hash"), salt: hex(p.salt, 16, "salt") };
1378
1386
  }
1379
1387
  function buildEscrowMsg(p) {
1380
1388
  const v = msgValues(p);
@@ -1436,6 +1444,9 @@ function delegateOptions(o) {
1436
1444
  if (!NEAR_ESCROW_CONTRACTS[o.network].includes(o.escrowContract)) {
1437
1445
  throw new Error(`escrowContract: not a registered Arras escrow for ${o.network}`);
1438
1446
  }
1447
+ delegateNonce(o);
1448
+ }
1449
+ function delegateNonce(o) {
1439
1450
  const nonce = uint(o.nonce, 64, "nonce");
1440
1451
  if (nonce === 0n) throw new Error("nonce must be positive");
1441
1452
  const height = uint(o.maxBlockHeight, 64, "maxBlockHeight");
@@ -1472,7 +1483,7 @@ function validateEscrowAuthorizationDelegate(d, o) {
1472
1483
  const gas = uint(a.gas, 64, "gas");
1473
1484
  if (gas < NEAR_ESCROW_MIN_GAS || gas > NEAR_ESCROW_MAX_GAS) throw new Error("FT gas outside 38..100 TGas");
1474
1485
  }
1475
- async function signDelegate(o, d) {
1486
+ async function signDelegate(o, d, scheme = "escrow") {
1476
1487
  const network = o.network;
1477
1488
  const pk = new Uint8Array(o.signer.publicKey);
1478
1489
  if (pk.length !== 32) throw new Error("Expected 32-byte Ed25519 public key");
@@ -1499,7 +1510,7 @@ async function signDelegate(o, d) {
1499
1510
  const signed = concat(bytes, Uint8Array.of(0), signature);
1500
1511
  return {
1501
1512
  x402Version: 2,
1502
- scheme: "escrow",
1513
+ scheme,
1503
1514
  network,
1504
1515
  payload: { signedDelegateAction: btoa(Array.from(signed, (b) => String.fromCharCode(b)).join("")) }
1505
1516
  };
@@ -1551,6 +1562,167 @@ var refund = (o, paymentId) => signEscrowLifecycle(o, "refund", { payment_id: pa
1551
1562
  var reclaim = (o, paymentId) => signEscrowLifecycle(o, "reclaim", { payment_id: paymentId });
1552
1563
  var withdraw = (o) => signEscrowLifecycle(o, "withdraw");
1553
1564
  var withdrawFor = (o, account2) => signEscrowLifecycle(o, "withdraw_for", { account: account2 });
1565
+ async function signExactNearDelegate(options) {
1566
+ const o = { ...options };
1567
+ if (o.network !== "near:mainnet" && o.network !== "near:testnet") throw new Error("Unsupported NEAR network");
1568
+ account(o.senderId, "senderId");
1569
+ account(o.payTo, "payTo");
1570
+ if (o.payTo === "intents.near") throw new Error("intents.near is not an allowed recipient");
1571
+ if (o.token !== NEAR_ESCROW_TOKENS[o.network]) throw new Error("token does not match network USDC");
1572
+ delegateNonce(o);
1573
+ const amount = uint(o.amount, 128, "amount");
1574
+ if (amount === 0n) throw new Error("amount must be positive");
1575
+ const gas = uint(o.gas ?? 30000000000000n, 64, "gas");
1576
+ if (gas === 0n || gas > 30000000000000n) throw new Error("Exact gas must be positive and at most 30 TGas");
1577
+ return signDelegate(o, {
1578
+ senderId: o.senderId,
1579
+ receiverId: o.token,
1580
+ nonce: o.nonce,
1581
+ maxBlockHeight: o.maxBlockHeight,
1582
+ actions: [{
1583
+ methodName: "ft_transfer",
1584
+ args: JSON.stringify({ receiver_id: o.payTo, amount: amount.toString() }),
1585
+ gas,
1586
+ deposit: 1n
1587
+ }]
1588
+ }, "exact");
1589
+ }
1590
+ function nep413Preimage(options) {
1591
+ const { message, recipient, callbackUrl, nonce } = options;
1592
+ if (typeof message !== "string") throw new Error("message must be a string");
1593
+ if (typeof recipient !== "string" || recipient.length === 0 || recipient.trim() !== recipient) {
1594
+ throw new Error("recipient must be a nonempty string without surrounding whitespace");
1595
+ }
1596
+ if (recipient.toLowerCase().replace(/\.$/u, "") === "intents.near") throw new Error("intents.near is not an allowed recipient");
1597
+ if (!(nonce instanceof Uint8Array) || nonce.length !== 32) throw new Error("nonce must contain 32 bytes");
1598
+ if (callbackUrl !== void 0 && typeof callbackUrl !== "string") throw new Error("callbackUrl must be a string");
1599
+ return concat(
1600
+ le(2147484061n, 4),
1601
+ str(message),
1602
+ new Uint8Array(nonce),
1603
+ str(recipient),
1604
+ callbackUrl === void 0 ? Uint8Array.of(0) : concat(Uint8Array.of(1), str(callbackUrl))
1605
+ );
1606
+ }
1607
+ async function signNep413(options) {
1608
+ const o = { ...options };
1609
+ account(o.accountId, "accountId");
1610
+ const digest = sha256.sha256(nep413Preimage(o));
1611
+ const pk = new Uint8Array(o.signer.publicKey);
1612
+ if (pk.length !== 32) throw new Error("Expected 32-byte Ed25519 public key");
1613
+ const signature = await o.signer.sign(digest.slice());
1614
+ if (!(signature instanceof Uint8Array) || signature.length !== 64 || !ed25519.ed25519.verify(signature, digest, pk)) {
1615
+ throw new Error("Invalid Ed25519 NEP-413 signature");
1616
+ }
1617
+ return {
1618
+ accountId: o.accountId,
1619
+ publicKey: `ed25519:${ethers.encodeBase58(pk)}`,
1620
+ signature: btoa(Array.from(signature, (b) => String.fromCharCode(b)).join(""))
1621
+ };
1622
+ }
1623
+
1624
+ // src/providers/near/storage.ts
1625
+ var NEAR_ARRAS_STORAGE_DEPOSIT = "50000000000000000000000";
1626
+ var NEAR_USDC_STORAGE_DEPOSIT = "1250000000000000000000";
1627
+ function storage(o, receiverId, registrationOnly, defaultDeposit) {
1628
+ if (o.network !== "near:mainnet" && o.network !== "near:testnet") throw new Error("Unsupported NEAR network");
1629
+ account(receiverId, "receiverId");
1630
+ if (receiverId === "intents.near") throw new Error("intents.near is not an allowed storage target");
1631
+ account(o.payerId, "payerId");
1632
+ const accountId = o.accountId ?? o.payerId;
1633
+ account(accountId, "accountId");
1634
+ const deposit = uint(o.deposit ?? defaultDeposit, 128, "deposit");
1635
+ if (deposit === 0n) throw new Error("storage deposit must be positive");
1636
+ return { signerId: o.payerId, receiverId, actions: [{ type: "FunctionCall", params: {
1637
+ methodName: "storage_deposit",
1638
+ args: { account_id: accountId, registration_only: registrationOnly },
1639
+ gas: "30000000000000",
1640
+ deposit: deposit.toString()
1641
+ } }] };
1642
+ }
1643
+ function buildArrasStorageDeposit(options) {
1644
+ const o = { ...options };
1645
+ if (o.network !== "near:mainnet" && o.network !== "near:testnet") throw new Error("Unsupported NEAR network");
1646
+ return storage(o, o.escrowContract, false, NEAR_ARRAS_STORAGE_DEPOSIT);
1647
+ }
1648
+ function buildUsdcStorageDeposit(options) {
1649
+ const o = { ...options };
1650
+ return storage(o, NEAR_ESCROW_TOKENS[o.network], true, NEAR_USDC_STORAGE_DEPOSIT);
1651
+ }
1652
+
1653
+ // src/providers/near/events.ts
1654
+ var string = (v) => typeof v === "string";
1655
+ var boolean = (v) => typeof v === "boolean";
1656
+ var integer = (bits) => (v) => {
1657
+ if (typeof v !== "string") return false;
1658
+ try {
1659
+ uint(v, bits, "event integer");
1660
+ return true;
1661
+ } catch {
1662
+ return false;
1663
+ }
1664
+ };
1665
+ var u128 = integer(128);
1666
+ var u64 = integer(64);
1667
+ var fee = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= 65535;
1668
+ var strings = (v) => Array.isArray(v) && v.every(string);
1669
+ var object = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1670
+ function record(required, optional = {}) {
1671
+ return (v) => object(v) && Object.entries(required).every(([k, check]) => Object.hasOwn(v, k) && check(v[k])) && Object.entries(optional).every(([k, check]) => !Object.hasOwn(v, k) || check(v[k]));
1672
+ }
1673
+ var operator = record({ operator_id: string }, {
1674
+ owner: string,
1675
+ capturers: strings,
1676
+ fee_bps: fee,
1677
+ fee_recipient: string,
1678
+ min_amount: u128,
1679
+ tope_tvl_operador: u128,
1680
+ tope_tvl_por_payer: u128,
1681
+ sponsor_max_por_payer: u128
1682
+ });
1683
+ var paymentAmount = record({ payment_id: string, amount: u128 });
1684
+ var pause = record({ by: string, paused: boolean, at: u64 });
1685
+ var checks = {
1686
+ authorized: record({
1687
+ payment_id: string,
1688
+ operator_id: string,
1689
+ token: string,
1690
+ payer: string,
1691
+ receiver: string,
1692
+ amount: u128,
1693
+ fee_bps: fee,
1694
+ fee_recipient: string,
1695
+ terms_hash: string
1696
+ }),
1697
+ released: record({ payment_id: string, amount: u128, net: u128, fee: u128 }),
1698
+ refunded: paymentAmount,
1699
+ reclaimed: paymentAmount,
1700
+ withdrawn: record({ account: string, token: string, amount: u128, ok: boolean }),
1701
+ compacted: record({ payment_id: string }),
1702
+ operator_registered: operator,
1703
+ operator_updated: operator,
1704
+ caps_set: record({ by: string, tope_por_pago: u128, tope_tvl_global: u128 }),
1705
+ paused: pause,
1706
+ unpaused: pause
1707
+ };
1708
+ function parseArrasEvents(logs) {
1709
+ const result = [];
1710
+ if (!Array.isArray(logs)) return result;
1711
+ for (const log of logs) {
1712
+ if (typeof log !== "string" || !log.startsWith("EVENT_JSON:")) continue;
1713
+ let value;
1714
+ try {
1715
+ value = JSON.parse(log.slice(11));
1716
+ } catch {
1717
+ continue;
1718
+ }
1719
+ if (!object(value) || value.standard !== "arras" || value.version !== "1.0.0" || typeof value.event !== "string" || !Object.hasOwn(checks, value.event) || !Array.isArray(value.data)) continue;
1720
+ const check = checks[value.event];
1721
+ if (!value.data.every(check)) continue;
1722
+ result.push({ standard: "arras", version: "1.0.0", event: value.event, data: value.data });
1723
+ }
1724
+ return result;
1725
+ }
1554
1726
 
1555
1727
  // src/providers/near/index.ts
1556
1728
  var NEAR_CONFIG = {
@@ -1631,7 +1803,7 @@ function serializeSignedDelegateAction(delegateActionBytes, signatureBytes) {
1631
1803
  ser.writeFixedBytes(signatureBytes);
1632
1804
  return ser.getBytes();
1633
1805
  }
1634
- async function sha2562(data) {
1806
+ async function sha2563(data) {
1635
1807
  const hashBuffer = await crypto.subtle.digest("SHA-256", data);
1636
1808
  return new Uint8Array(hashBuffer);
1637
1809
  }
@@ -1875,7 +2047,7 @@ var NEARProvider = class {
1875
2047
  const hashInput = new Uint8Array(NEP366_PREFIX.length + delegateActionBytes.length);
1876
2048
  hashInput.set(NEP366_PREFIX, 0);
1877
2049
  hashInput.set(delegateActionBytes, NEP366_PREFIX.length);
1878
- const delegateHash = await sha2562(hashInput);
2050
+ const delegateHash = await sha2563(hashInput);
1879
2051
  const signature = await this.signMessage(delegateHash);
1880
2052
  const signedDelegateActionBytes = serializeSignedDelegateAction(
1881
2053
  delegateActionBytes,
@@ -2084,21 +2256,29 @@ var NEARProvider = class {
2084
2256
  var near_default = NEARProvider;
2085
2257
 
2086
2258
  exports.NEARProvider = NEARProvider;
2259
+ exports.NEAR_ARRAS_STORAGE_DEPOSIT = NEAR_ARRAS_STORAGE_DEPOSIT;
2087
2260
  exports.NEAR_ESCROW_CONTRACTS = NEAR_ESCROW_CONTRACTS;
2088
2261
  exports.NEAR_ESCROW_MAX_GAS = NEAR_ESCROW_MAX_GAS;
2089
2262
  exports.NEAR_ESCROW_MIN_GAS = NEAR_ESCROW_MIN_GAS;
2090
2263
  exports.NEAR_ESCROW_TOKENS = NEAR_ESCROW_TOKENS;
2264
+ exports.NEAR_USDC_STORAGE_DEPOSIT = NEAR_USDC_STORAGE_DEPOSIT;
2265
+ exports.buildArrasStorageDeposit = buildArrasStorageDeposit;
2091
2266
  exports.buildEscrowAuthorizationDelegate = buildEscrowAuthorizationDelegate;
2092
2267
  exports.buildEscrowMsg = buildEscrowMsg;
2268
+ exports.buildUsdcStorageDeposit = buildUsdcStorageDeposit;
2093
2269
  exports.computePaymentId = computePaymentId;
2094
2270
  exports.createNearLocalSigner = createNearLocalSigner;
2095
2271
  exports.default = near_default;
2272
+ exports.nep413Preimage = nep413Preimage;
2273
+ exports.parseArrasEvents = parseArrasEvents;
2096
2274
  exports.paymentIdPreimage = paymentIdPreimage;
2097
2275
  exports.reclaim = reclaim;
2098
2276
  exports.refund = refund;
2099
2277
  exports.release = release;
2100
2278
  exports.signEscrowAuthorization = signEscrowAuthorization;
2101
2279
  exports.signEscrowLifecycle = signEscrowLifecycle;
2280
+ exports.signExactNearDelegate = signExactNearDelegate;
2281
+ exports.signNep413 = signNep413;
2102
2282
  exports.validateEscrowAuthorizationDelegate = validateEscrowAuthorizationDelegate;
2103
2283
  exports.withdraw = withdraw;
2104
2284
  exports.withdrawFor = withdrawFor;