@heyanon-arp/sdk 0.0.9 → 0.0.10

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/index.mjs CHANGED
@@ -165,56 +165,6 @@ var SETTLEMENT_PURPOSES = [
165
165
  Purpose.SOLANA_RESOLVE_DISPUTE
166
166
  ];
167
167
 
168
- // src/cosignature/cosign.ts
169
- var COSIGN_ALLOWED = [Purpose.RECEIPT, Purpose.DISPUTE_RESPONSE];
170
- function signCosignature(input) {
171
- const purpose = input.payload.purpose;
172
- if (!COSIGN_ALLOWED.includes(purpose)) {
173
- throw new Error(`signCosignature: purpose "${purpose}" is not allowed for co_signature`);
174
- }
175
- const digest = sha256(canonicalBytes(input.payload));
176
- const sigBytes = sign2(digest, input.identitySecretKey);
177
- const payload_hash = `sha256:${bytesToHex2(digest)}`;
178
- const sig = `ed25519:${base64.encode(sigBytes)}`;
179
- return {
180
- agent_did: input.signerDid,
181
- purpose,
182
- payload_hash,
183
- sig
184
- };
185
- }
186
- function verifyCosignature(input) {
187
- if (input.cosignature.purpose !== input.payload.purpose) {
188
- return { ok: false, reason: "purpose_mismatch" };
189
- }
190
- const digest = sha256(canonicalBytes(input.payload));
191
- const expectedHash = `sha256:${bytesToHex2(digest)}`;
192
- if (expectedHash !== input.cosignature.payload_hash) {
193
- return { ok: false, reason: "payload_hash_mismatch" };
194
- }
195
- const sigPrefix = "ed25519:";
196
- if (!input.cosignature.sig.startsWith(sigPrefix)) {
197
- return { ok: false, reason: "signature_malformed", detail: "sig missing ed25519: prefix" };
198
- }
199
- let sigBytes;
200
- try {
201
- sigBytes = base64.decode(input.cosignature.sig.slice(sigPrefix.length));
202
- } catch {
203
- return { ok: false, reason: "signature_malformed", detail: "sig base64 decode failed" };
204
- }
205
- if (sigBytes.length !== 64) {
206
- return { ok: false, reason: "signature_malformed", detail: `expected 64-byte signature, got ${sigBytes.length}` };
207
- }
208
- return verify2(sigBytes, digest, input.signerIdentityPubkey) ? { ok: true } : { ok: false, reason: "signature_invalid" };
209
- }
210
- function bytesToHex2(b) {
211
- let s = "";
212
- for (let i = 0; i < b.length; i++) {
213
- s += b[i].toString(16).padStart(2, "0");
214
- }
215
- return s;
216
- }
217
-
218
168
  // src/challenge/challenge.ts
219
169
  var CHALLENGE_PURPOSE_BYTES = new TextEncoder().encode(Purpose.CHALLENGE);
220
170
  function buildSigningInput(challengeBytes) {
@@ -308,7 +258,7 @@ function verifyKeyLinkAttestation(attestation, scryptKey) {
308
258
  function signedMessageHash(envelope) {
309
259
  const input = envelope.attachments === void 0 ? { protected: envelope.protected, body: envelope.body } : { protected: envelope.protected, body: envelope.body, attachments: envelope.attachments };
310
260
  const digest = sha256(canonicalBytes(input));
311
- return `sha256:${bytesToHex3(digest)}`;
261
+ return `sha256:${bytesToHex2(digest)}`;
312
262
  }
313
263
  function serverEventHash(input) {
314
264
  const canonicalInput = {
@@ -319,7 +269,7 @@ function serverEventHash(input) {
319
269
  sender_signature: input.senderSignature
320
270
  };
321
271
  const digest = sha256(canonicalBytes(canonicalInput));
322
- return `sha256:${bytesToHex3(digest)}`;
272
+ return `sha256:${bytesToHex2(digest)}`;
323
273
  }
324
274
  function findFirstChainDivergence(events) {
325
275
  for (let i = 0; i < events.length; i++) {
@@ -336,185 +286,13 @@ function findFirstChainDivergence(events) {
336
286
  }
337
287
  return null;
338
288
  }
339
- function bytesToHex3(b) {
289
+ function bytesToHex2(b) {
340
290
  let s = "";
341
291
  for (let i = 0; i < b.length; i++) {
342
292
  s += b[i].toString(16).padStart(2, "0");
343
293
  }
344
294
  return s;
345
295
  }
346
- function deriveLockId(delegationId) {
347
- const bytes16 = delegationIdToBytes16(delegationId);
348
- const prefix = new TextEncoder().encode("arp-lock-v1");
349
- const input = new Uint8Array(prefix.length + 16);
350
- input.set(prefix, 0);
351
- input.set(bytes16, prefix.length);
352
- return sha256(input);
353
- }
354
- var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
355
- function delegationIdToBytes16(delegationId) {
356
- const uuid = delegationId.startsWith("del_") ? delegationId.slice(4) : delegationId;
357
- if (!UUID_RE.test(uuid)) {
358
- if (delegationId.startsWith("del_")) {
359
- throw new Error(`Invalid delegation_id UUID (must be canonical lowercase): ${JSON.stringify(uuid)}`);
360
- }
361
- throw new Error(`Invalid delegation_id format: expected "del_<uuid>" or bare canonical-lowercase UUID, got ${JSON.stringify(delegationId)}`);
362
- }
363
- const hex = uuid.replace(/-/g, "");
364
- const out = new Uint8Array(16);
365
- for (let i = 0; i < 16; i++) {
366
- out[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
367
- }
368
- return out;
369
- }
370
- function bytes16ToDelegationId(bytes) {
371
- if (bytes.length !== 16) {
372
- throw new Error(`bytes16ToDelegationId: expected 16 bytes, got ${bytes.length}`);
373
- }
374
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
375
- return `del_${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
376
- }
377
-
378
- // src/settlement/settlement.ts
379
- var PURPOSE_RELEASE_STRING = "ARP-SOLANA-RELEASE-v1.5";
380
- var PURPOSE_PARTIAL_RELEASE_STRING = "ARP-SOLANA-PARTIAL-RELEASE-v1.5";
381
- var PURPOSE_REFUND_STRING = "ARP-SOLANA-REFUND-v1";
382
- var PURPOSE_RELEASE = new TextEncoder().encode(PURPOSE_RELEASE_STRING);
383
- var PURPOSE_PARTIAL_RELEASE = new TextEncoder().encode(PURPOSE_PARTIAL_RELEASE_STRING);
384
- var PURPOSE_REFUND = new TextEncoder().encode(PURPOSE_REFUND_STRING);
385
- var ZERO_PUBKEY = new Uint8Array(32);
386
- function buildReleaseDigest(input) {
387
- requireLen(input.programId, 32, "programId");
388
- requireLen(input.lockId, 32, "lockId");
389
- requireLen(input.payerSettlementPubkey, 32, "payerSettlementPubkey");
390
- requireLen(input.payeeSettlementPubkey, 32, "payeeSettlementPubkey");
391
- requireLen(input.mint, 32, "mint");
392
- requireLen(input.conditionHash, 32, "conditionHash");
393
- requireLen(input.receiptEventHash, 32, "receiptEventHash");
394
- requireLen(input.deliverableHash, 32, "deliverableHash");
395
- const feeBps = input.feeBpsAtLock ?? 0;
396
- requireFeeBps(feeBps);
397
- const feeRecipient = input.feeRecipientAtLock ?? ZERO_PUBKEY;
398
- requireLen(feeRecipient, 32, "feeRecipientAtLock");
399
- const delegationBytes = delegationIdToBytes16(input.delegationId);
400
- const buf = concatBytes(
401
- PURPOSE_RELEASE,
402
- new Uint8Array([input.clusterTag]),
403
- input.programId,
404
- input.lockId,
405
- input.payerSettlementPubkey,
406
- input.payeeSettlementPubkey,
407
- input.mint,
408
- u64LE(input.amount),
409
- input.conditionHash,
410
- delegationBytes,
411
- input.receiptEventHash,
412
- input.deliverableHash,
413
- u64LE(input.expiresAt),
414
- u16LE(feeBps),
415
- feeRecipient
416
- );
417
- return sha256(buf);
418
- }
419
- function buildPartialReleaseDigest(input) {
420
- requireLen(input.programId, 32, "programId");
421
- requireLen(input.lockId, 32, "lockId");
422
- requireLen(input.payerSettlementPubkey, 32, "payerSettlementPubkey");
423
- requireLen(input.payeeSettlementPubkey, 32, "payeeSettlementPubkey");
424
- requireLen(input.mint, 32, "mint");
425
- requireLen(input.conditionHash, 32, "conditionHash");
426
- requireLen(input.receiptEventHash, 32, "receiptEventHash");
427
- requireLen(input.deliverableHash, 32, "deliverableHash");
428
- const feeBps = input.feeBpsAtLock ?? 0;
429
- requireFeeBps(feeBps);
430
- const feeRecipient = input.feeRecipientAtLock ?? ZERO_PUBKEY;
431
- requireLen(feeRecipient, 32, "feeRecipientAtLock");
432
- const delegationBytes = delegationIdToBytes16(input.delegationId);
433
- const buf = concatBytes(
434
- PURPOSE_PARTIAL_RELEASE,
435
- new Uint8Array([input.clusterTag]),
436
- input.programId,
437
- input.lockId,
438
- input.payerSettlementPubkey,
439
- input.payeeSettlementPubkey,
440
- input.mint,
441
- u64LE(input.amount),
442
- u64LE(input.payeeAmount),
443
- input.conditionHash,
444
- delegationBytes,
445
- input.receiptEventHash,
446
- input.deliverableHash,
447
- u64LE(input.expiresAt),
448
- u16LE(feeBps),
449
- feeRecipient
450
- );
451
- return sha256(buf);
452
- }
453
- var REFUND_REASON_BYTES = {
454
- expired: 0,
455
- dispute_resolution: 1,
456
- payer_cancellation: 2,
457
- both_parties_agreed: 3
458
- };
459
- function buildRefundDigest(input) {
460
- requireLen(input.programId, 32, "programId");
461
- requireLen(input.lockId, 32, "lockId");
462
- requireLen(input.payerSettlementPubkey, 32, "payerSettlementPubkey");
463
- requireLen(input.payeeSettlementPubkey, 32, "payeeSettlementPubkey");
464
- requireLen(input.mint, 32, "mint");
465
- const buf = concatBytes(
466
- PURPOSE_REFUND,
467
- new Uint8Array([input.clusterTag]),
468
- input.programId,
469
- input.lockId,
470
- input.payerSettlementPubkey,
471
- input.payeeSettlementPubkey,
472
- input.mint,
473
- u64LE(input.amount),
474
- new Uint8Array([input.reasonByte]),
475
- u64LE(input.expiresAt)
476
- );
477
- return sha256(buf);
478
- }
479
- function requireLen(bytes, expected, name) {
480
- if (bytes.length !== expected) {
481
- throw new Error(`settlement digest: ${name} must be ${expected} bytes, got ${bytes.length}`);
482
- }
483
- }
484
- function requireFeeBps(bps) {
485
- if (!Number.isInteger(bps) || bps < 0 || bps > 65535) {
486
- throw new Error(`settlement digest: feeBpsAtLock must be a u16 (0..65535), got ${bps}`);
487
- }
488
- }
489
- function concatBytes(...parts) {
490
- let total = 0;
491
- for (const p of parts) total += p.length;
492
- const out = new Uint8Array(total);
493
- let off = 0;
494
- for (const p of parts) {
495
- out.set(p, off);
496
- off += p.length;
497
- }
498
- return out;
499
- }
500
- function u64LE(value) {
501
- if (value < 0n || value > 0xffffffffffffffffn) {
502
- throw new Error(`settlement digest: u64 value out of range: ${value}`);
503
- }
504
- const out = new Uint8Array(8);
505
- let v = value;
506
- for (let i = 0; i < 8; i++) {
507
- out[i] = Number(v & 0xffn);
508
- v >>= 8n;
509
- }
510
- return out;
511
- }
512
- function u16LE(value) {
513
- const out = new Uint8Array(2);
514
- out[0] = value & 255;
515
- out[1] = value >> 8 & 255;
516
- return out;
517
- }
518
296
 
519
297
  // src/settlement/token-program.ts
520
298
  var SPL_TOKEN_PROGRAM_ID_BASE58 = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
@@ -633,32 +411,65 @@ var SOLANA_CLUSTER_IDS = {
633
411
  "solana-devnet": "EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
634
412
  };
635
413
  var SLIP44_SOLANA = 501;
414
+ var MAINNET_MINTS = {
415
+ USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
416
+ USDT: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
417
+ ANON: "9McvH6w97oewLmPxqQEoHUAv3u5iYMyQ9AeZZhguYf1T"
418
+ };
636
419
  var USDC_MINTS = {
637
- "solana-mainnet": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
420
+ "solana-mainnet": MAINNET_MINTS.USDC,
638
421
  "solana-devnet": "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"
639
422
  };
640
- var WELL_KNOWN_ASSETS = {
641
- "USDC:solana-mainnet": {
642
- asset_id: `solana:${SOLANA_CLUSTER_IDS["solana-mainnet"]}/spl:${USDC_MINTS["solana-mainnet"]}`,
643
- decimals: 6,
644
- symbol: "USDC"
645
- },
646
- "USDC:solana-devnet": {
647
- asset_id: `solana:${SOLANA_CLUSTER_IDS["solana-devnet"]}/spl:${USDC_MINTS["solana-devnet"]}`,
648
- decimals: 6,
649
- symbol: "USDC"
650
- },
651
- "SOL:solana-mainnet": {
652
- asset_id: `solana:${SOLANA_CLUSTER_IDS["solana-mainnet"]}/slip44:${SLIP44_SOLANA}`,
653
- decimals: 9,
654
- symbol: "SOL"
655
- },
656
- "SOL:solana-devnet": {
657
- asset_id: `solana:${SOLANA_CLUSTER_IDS["solana-devnet"]}/slip44:${SLIP44_SOLANA}`,
658
- decimals: 9,
659
- symbol: "SOL"
660
- }
423
+ var SOL_MAINNET = {
424
+ asset_id: `solana:${SOLANA_CLUSTER_IDS["solana-mainnet"]}/slip44:${SLIP44_SOLANA}`,
425
+ decimals: 9,
426
+ symbol: "SOL"
661
427
  };
428
+ var SOL_DEVNET = {
429
+ asset_id: `solana:${SOLANA_CLUSTER_IDS["solana-devnet"]}/slip44:${SLIP44_SOLANA}`,
430
+ decimals: 9,
431
+ symbol: "SOL"
432
+ };
433
+ var ASSET_WHITELIST = {
434
+ "solana-mainnet": [
435
+ SOL_MAINNET,
436
+ {
437
+ asset_id: `solana:${SOLANA_CLUSTER_IDS["solana-mainnet"]}/spl:${MAINNET_MINTS.USDC}`,
438
+ decimals: 6,
439
+ symbol: "USDC"
440
+ },
441
+ {
442
+ asset_id: `solana:${SOLANA_CLUSTER_IDS["solana-mainnet"]}/spl:${MAINNET_MINTS.USDT}`,
443
+ decimals: 6,
444
+ symbol: "USDT"
445
+ },
446
+ {
447
+ asset_id: `solana:${SOLANA_CLUSTER_IDS["solana-mainnet"]}/spl:${MAINNET_MINTS.ANON}`,
448
+ decimals: 9,
449
+ symbol: "ANON"
450
+ }
451
+ ],
452
+ "solana-devnet": [SOL_DEVNET]
453
+ };
454
+ var WELL_KNOWN_ASSETS = Object.fromEntries(
455
+ Object.entries(ASSET_WHITELIST).flatMap(([cluster, assets]) => assets.map((asset) => [`${asset.symbol}:${cluster}`, asset]))
456
+ );
457
+ var WELL_KNOWN_ASSET_KEYS = Object.keys(WELL_KNOWN_ASSETS);
458
+ function listWhitelistedAssets(cluster) {
459
+ return ASSET_WHITELIST[cluster].map((a) => ({ ...a }));
460
+ }
461
+ function findAssetByAssetId(assetId) {
462
+ for (const [cluster, assets] of Object.entries(ASSET_WHITELIST)) {
463
+ const asset = assets.find((a) => a.asset_id === assetId);
464
+ if (asset) return { asset: { ...asset }, cluster, key: `${asset.symbol}:${cluster}` };
465
+ }
466
+ return null;
467
+ }
468
+ function isWhitelistedAssetId(assetId, cluster) {
469
+ const hit = findAssetByAssetId(assetId);
470
+ if (!hit) return false;
471
+ return cluster === void 0 || hit.cluster === cluster;
472
+ }
662
473
  var CAIP19_REGEX = /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}\/[-a-z0-9]{3,8}:[-.%a-zA-Z0-9]{1,128}$/;
663
474
  function isAssetIdentifier(value) {
664
475
  if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
@@ -672,22 +483,54 @@ function resolveAsset(input) {
672
483
  const hit = WELL_KNOWN_ASSETS[input];
673
484
  if (hit) return { ...hit };
674
485
  if (CAIP19_REGEX.test(input)) {
486
+ const whitelisted = findAssetByAssetId(input);
487
+ if (whitelisted) return whitelisted.asset;
675
488
  return { asset_id: input, decimals: NaN };
676
489
  }
677
490
  return null;
678
491
  }
679
- var WELL_KNOWN_ASSET_KEYS = Object.keys(WELL_KNOWN_ASSETS);
492
+ function deriveLockId(delegationId) {
493
+ const bytes16 = delegationIdToBytes16(delegationId);
494
+ const prefix = new TextEncoder().encode("arp-lock-v1");
495
+ const input = new Uint8Array(prefix.length + 16);
496
+ input.set(prefix, 0);
497
+ input.set(bytes16, prefix.length);
498
+ return sha256(input);
499
+ }
500
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
501
+ function delegationIdToBytes16(delegationId) {
502
+ const uuid = delegationId.startsWith("del_") ? delegationId.slice(4) : delegationId;
503
+ if (!UUID_RE.test(uuid)) {
504
+ if (delegationId.startsWith("del_")) {
505
+ throw new Error(`Invalid delegation_id UUID (must be canonical lowercase): ${JSON.stringify(uuid)}`);
506
+ }
507
+ throw new Error(`Invalid delegation_id format: expected "del_<uuid>" or bare canonical-lowercase UUID, got ${JSON.stringify(delegationId)}`);
508
+ }
509
+ const hex = uuid.replace(/-/g, "");
510
+ const out = new Uint8Array(16);
511
+ for (let i = 0; i < 16; i++) {
512
+ out[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
513
+ }
514
+ return out;
515
+ }
516
+ function bytes16ToDelegationId(bytes) {
517
+ if (bytes.length !== 16) {
518
+ throw new Error(`bytes16ToDelegationId: expected 16 bytes, got ${bytes.length}`);
519
+ }
520
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
521
+ return `del_${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
522
+ }
680
523
  function deriveDelegationConditionHash(delegation) {
681
- const required = ["delegationId", "scopeSummary", "pricingModel"];
524
+ const required = ["delegationId", "scopeSummary"];
682
525
  for (const field of required) {
683
526
  if (delegation[field] === void 0) {
684
527
  throw new Error(`deriveDelegationConditionHash: required field '${String(field)}' is missing from the delegation input`);
685
528
  }
686
529
  }
687
530
  const subset = {
531
+ v: "arp-condition-v2",
688
532
  delegationId: delegation.delegationId,
689
- scopeSummary: delegation.scopeSummary,
690
- pricingModel: delegation.pricingModel
533
+ scopeSummary: delegation.scopeSummary
691
534
  };
692
535
  if (delegation.currency !== void 0) subset.currency = delegation.currency;
693
536
  const bytes = canonicalBytes(subset);
@@ -716,15 +559,16 @@ function parseCaip19SolanaAssetId(assetId) {
716
559
  throw new Error(`Unsupported CAIP-19 namespace: ${JSON.stringify(namespaceRaw)} (only 'spl' and 'slip44' are supported on Solana)`);
717
560
  }
718
561
  var CREATE_LOCK_DISCRIMINATOR = new Uint8Array([171, 216, 92, 167, 165, 8, 153, 90]);
719
- function buildCreateLockIxData(args) {
562
+ var CREATE_LOCK_NATIVE_DISCRIMINATOR = new Uint8Array([234, 19, 218, 36, 23, 74, 218, 108]);
563
+ function buildCreateLockIxData(args, opts = {}) {
720
564
  if (args.lockId.length !== 32) throw new Error("create_lock: lockId must be 32 bytes");
721
565
  if (args.conditionHash.length !== 32) throw new Error("create_lock: conditionHash must be 32 bytes");
722
566
  requireU64(args.amount, "amount");
723
- requireU64(args.expiry, "expiry");
724
- const total = 8 + 32 + 8 + 32 + 8;
567
+ const disc = opts.native ? CREATE_LOCK_NATIVE_DISCRIMINATOR : CREATE_LOCK_DISCRIMINATOR;
568
+ const total = 8 + 32 + 8 + 32;
725
569
  const out = new Uint8Array(total);
726
570
  let off = 0;
727
- out.set(CREATE_LOCK_DISCRIMINATOR, off);
571
+ out.set(disc, off);
728
572
  off += 8;
729
573
  out.set(args.lockId, off);
730
574
  off += 32;
@@ -732,8 +576,6 @@ function buildCreateLockIxData(args) {
732
576
  off += 8;
733
577
  out.set(args.conditionHash, off);
734
578
  off += 32;
735
- writeU64LE(out, off, args.expiry);
736
- off += 8;
737
579
  if (off !== total) throw new Error(`create_lock ix data layout drift: ${off} != ${total}`);
738
580
  return out;
739
581
  }
@@ -753,5 +595,104 @@ function computeCreateLockDiscriminator() {
753
595
  const h = sha256(new TextEncoder().encode("global:create_lock"));
754
596
  return h.slice(0, 8);
755
597
  }
598
+ var ESCROW_PDA_SEEDS = {
599
+ LOCK: "lock",
600
+ ESCROW: "escrow",
601
+ CONFIG: "config",
602
+ STAKE_VAULT: "stake_vault",
603
+ COLLATERAL: "collateral",
604
+ DISPUTE_RESOLUTION: "dispute_resolution",
605
+ OPERATOR_AUTH: "operator_auth",
606
+ EVENT_AUTHORITY: "__event_authority"
607
+ };
608
+ var NO_ARG_LIFECYCLE_INSTRUCTIONS = [
609
+ "accept_lock",
610
+ "submit_work",
611
+ "claim_work_payment",
612
+ "claim_work_payment_native",
613
+ "cancel_lock",
614
+ "cancel_lock_native",
615
+ "claim_expired_work",
616
+ "claim_expired_work_native",
617
+ "open_dispute",
618
+ "close_dispute",
619
+ "close_dispute_native"
620
+ ];
621
+ function instructionDiscriminator(ixName) {
622
+ return sha256(new TextEncoder().encode(`global:${ixName}`)).slice(0, 8);
623
+ }
624
+ function buildLifecycleIxData(ixName) {
625
+ if (!NO_ARG_LIFECYCLE_INSTRUCTIONS.includes(ixName)) {
626
+ throw new Error(`buildLifecycleIxData: '${ixName}' is not a no-arg lifecycle instruction`);
627
+ }
628
+ return instructionDiscriminator(ixName);
629
+ }
630
+ function buildResolveDisputeIxData(args, opts = {}) {
631
+ if (args.reasonHash.length !== 32) throw new Error("resolve_dispute: reasonHash must be 32 bytes");
632
+ if (args.disputeId.length !== 16) throw new Error("resolve_dispute: disputeId must be 16 bytes");
633
+ const disc = instructionDiscriminator(opts.native ? "resolve_dispute_native" : "resolve_dispute");
634
+ const total = 8 + 1 + 32 + 16;
635
+ const out = new Uint8Array(total);
636
+ out.set(disc, 0);
637
+ out[8] = args.isPayerWinner ? 1 : 0;
638
+ out.set(args.reasonHash, 9);
639
+ out.set(args.disputeId, 41);
640
+ return out;
641
+ }
642
+ var LOCK_ACCOUNT_SIZE = 269;
643
+ var LOCK_ACCOUNT_DISCRIMINATOR = new Uint8Array([8, 255, 36, 202, 210, 22, 57, 137]);
644
+ var LOCK_STATE_NAMES = ["created", "canceled", "in_progress", "submitted", "paid", "revoked", "disputing", "dispute_resolved", "dispute_closed"];
645
+ var LOCK_TERMINAL_STATES = ["canceled", "paid", "revoked", "dispute_resolved", "dispute_closed"];
646
+ var NATIVE_SOL_MINT_BASE58 = "11111111111111111111111111111111";
647
+ function decodeLockAccount(data) {
648
+ if (data.length !== LOCK_ACCOUNT_SIZE) {
649
+ throw new Error(`decodeLockAccount: expected ${LOCK_ACCOUNT_SIZE} bytes, got ${data.length}`);
650
+ }
651
+ for (let i = 0; i < 8; i++) {
652
+ if (data[i] !== LOCK_ACCOUNT_DISCRIMINATOR[i]) {
653
+ throw new Error("decodeLockAccount: account discriminator is not Lock");
654
+ }
655
+ }
656
+ const stateByte = data[185];
657
+ const state = LOCK_STATE_NAMES[stateByte];
658
+ if (state === void 0) {
659
+ throw new Error(`decodeLockAccount: unknown LockState discriminant ${stateByte}`);
660
+ }
661
+ const mint = base58.encode(data.slice(113, 145));
662
+ return {
663
+ lockId: toHex(data.subarray(8, 40)),
664
+ version: data[40],
665
+ payer: base58.encode(data.slice(41, 73)),
666
+ payee: base58.encode(data.slice(73, 105)),
667
+ amount: readU64LE(data, 105),
668
+ mint,
669
+ isNative: mint === NATIVE_SOL_MINT_BASE58,
670
+ conditionHash: toHex(data.subarray(145, 177)),
671
+ expiry: readU64LE(data, 177),
672
+ state,
673
+ stateByte,
674
+ feeBpsAtLock: data[186] | data[187] << 8,
675
+ feeRecipientAtLock: base58.encode(data.slice(188, 220)),
676
+ workerStakeAtLock: readU64LE(data, 220),
677
+ operatorDisputeFeeAtLock: readU64LE(data, 228),
678
+ treasuryAtLock: base58.encode(data.slice(236, 268)),
679
+ bump: data[268]
680
+ };
681
+ }
682
+ function computeLockAccountDiscriminator() {
683
+ return sha256(new TextEncoder().encode("account:Lock")).slice(0, 8);
684
+ }
685
+ function toHex(bytes) {
686
+ let hex = "";
687
+ for (const b of bytes) hex += b.toString(16).padStart(2, "0");
688
+ return hex;
689
+ }
690
+ function readU64LE(buf, off) {
691
+ let v = 0n;
692
+ for (let i = 0; i < 8; i++) {
693
+ v |= BigInt(buf[off + i]) << BigInt(8 * i);
694
+ }
695
+ return v;
696
+ }
756
697
 
757
- export { CAIP19_REGEX, COSIGNATURE_PURPOSES, CREATE_LOCK_DISCRIMINATOR, DECLINE_REASONS, PROTECTED_PURPOSES, PURPOSE_PARTIAL_RELEASE_STRING, PURPOSE_REFUND_STRING, PURPOSE_RELEASE_STRING, Purpose, REFUND_REASON_BYTES, SCRYPT_PARAMS, SETTLEMENT_PURPOSES, SLIP44_SOLANA, SOLANA_CLUSTER_IDS, SPL_TOKEN_PROGRAM_ID_BASE58, USDC_MINTS, WELL_KNOWN_ASSETS, WELL_KNOWN_ASSET_KEYS, base58btcDecode, base58btcEncode, buildCreateLockIxData, buildPartialReleaseDigest, buildRefundDigest, buildReleaseDigest, bytes16ToDelegationId, canonicalBytes, canonicalJson, canonicalSha256Hex, computeCreateLockDiscriminator, delegationIdToBytes16, deriveDelegationConditionHash, deriveLockId, deriveScryptKey, detectTokenProgramFromOwner, detectTokenProgramFromOwnerBytes, expiresAt, findFirstChainDivergence, formatDid, generateKeyPair, getPublicKey2 as getPublicKey, isAssetIdentifier, isDeclineReason, isValidDid, parseCaip19SolanaAssetId, parseDid, pollUntil, resolveAsset, rfc3339, scryptPasswordProofSign, scryptPasswordProofVerify, senderNonce, serverEventHash, sign2 as sign, signChallenge, signCosignature, signEnvelope, signKeyLinkAttestation, signedMessageHash, uuidV4, verify2 as verify, verifyChallenge, verifyCosignature, verifyEnvelope, verifyKeyLinkAttestation };
698
+ export { ASSET_WHITELIST, CAIP19_REGEX, COSIGNATURE_PURPOSES, CREATE_LOCK_DISCRIMINATOR, CREATE_LOCK_NATIVE_DISCRIMINATOR, DECLINE_REASONS, ESCROW_PDA_SEEDS, LOCK_ACCOUNT_DISCRIMINATOR, LOCK_ACCOUNT_SIZE, LOCK_STATE_NAMES, LOCK_TERMINAL_STATES, MAINNET_MINTS, NATIVE_SOL_MINT_BASE58, NO_ARG_LIFECYCLE_INSTRUCTIONS, PROTECTED_PURPOSES, Purpose, SCRYPT_PARAMS, SETTLEMENT_PURPOSES, SLIP44_SOLANA, SOLANA_CLUSTER_IDS, SPL_TOKEN_PROGRAM_ID_BASE58, USDC_MINTS, WELL_KNOWN_ASSETS, WELL_KNOWN_ASSET_KEYS, base58btcDecode, base58btcEncode, buildCreateLockIxData, buildLifecycleIxData, buildResolveDisputeIxData, bytes16ToDelegationId, canonicalBytes, canonicalJson, canonicalSha256Hex, computeCreateLockDiscriminator, computeLockAccountDiscriminator, decodeLockAccount, delegationIdToBytes16, deriveDelegationConditionHash, deriveLockId, deriveScryptKey, detectTokenProgramFromOwner, detectTokenProgramFromOwnerBytes, expiresAt, findAssetByAssetId, findFirstChainDivergence, formatDid, generateKeyPair, getPublicKey2 as getPublicKey, instructionDiscriminator, isAssetIdentifier, isDeclineReason, isValidDid, isWhitelistedAssetId, listWhitelistedAssets, parseCaip19SolanaAssetId, parseDid, pollUntil, resolveAsset, rfc3339, scryptPasswordProofSign, scryptPasswordProofVerify, senderNonce, serverEventHash, sign2 as sign, signChallenge, signEnvelope, signKeyLinkAttestation, signedMessageHash, uuidV4, verify2 as verify, verifyChallenge, verifyEnvelope, verifyKeyLinkAttestation };
@@ -1,4 +1,2 @@
1
- export { buildReleaseDigest, buildPartialReleaseDigest, buildRefundDigest, REFUND_REASON_BYTES, PURPOSE_RELEASE_STRING, PURPOSE_PARTIAL_RELEASE_STRING, PURPOSE_REFUND_STRING, } from './settlement';
2
- export type { ReleaseDigestInput, PartialReleaseDigestInput, RefundDigestInput, RefundReasonByte } from './settlement';
3
1
  export { detectTokenProgramFromOwner, detectTokenProgramFromOwnerBytes, SPL_TOKEN_PROGRAM_ID_BASE58 } from './token-program';
4
2
  export type { TokenProgramKind, TokenProgramDetection } from './token-program';
@@ -1,4 +1,3 @@
1
- import type { PricingModel } from './body';
2
1
  /**
3
2
  * Agent accept-preferences ("PricingPolicy") — the worker-side "what I
4
3
  * accept" constraints a registered agent publishes on its profile.
@@ -21,11 +20,6 @@ import type { PricingModel } from './body';
21
20
  * same replace semantics as `tags`.
22
21
  */
23
22
  export interface AcceptPrefs {
24
- /**
25
- * Accepted pricing models. Empty/absent ⇒ any model. Subset of the
26
- * closed `PricingModel` set.
27
- */
28
- pricingModels?: PricingModel[];
29
23
  /**
30
24
  * Accepted currencies with optional per-currency amount bounds.
31
25
  * Empty/absent ⇒ any currency, no amount bound. An offer whose