@heyanon-arp/sdk 0.0.35 → 0.0.36
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/assets.d.ts +14 -0
- package/dist/index.js +91 -78
- package/dist/index.mjs +91 -79
- package/dist/types/agent.d.ts +52 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/assets.d.ts
CHANGED
|
@@ -91,6 +91,20 @@ export declare function findAssetByAssetId(assetId: string): {
|
|
|
91
91
|
cluster: SolanaCluster;
|
|
92
92
|
key: string;
|
|
93
93
|
} | null;
|
|
94
|
+
/**
|
|
95
|
+
* Best-effort mint → display metadata, for labelling settlement-volume buckets.
|
|
96
|
+
* - native SOL sentinel → `{ SOL, 9 }` (assetId null: the `slip44` CAIP-19 is
|
|
97
|
+
* cluster-specific and the bare mint can't disambiguate devnet/mainnet);
|
|
98
|
+
* - SPL mint → the EXACT whitelist entry (an SPL mint is cluster-unique, so
|
|
99
|
+
* symbol + decimals + asset_id are precise);
|
|
100
|
+
* - unrecognised mint → all null (the caller still has the raw mint + the
|
|
101
|
+
* base-unit sum, so the figure is never lost — just unlabelled).
|
|
102
|
+
*/
|
|
103
|
+
export declare function findAssetMetaByMint(mint: string): {
|
|
104
|
+
assetId: string | null;
|
|
105
|
+
symbol: string | null;
|
|
106
|
+
decimals: number | null;
|
|
107
|
+
};
|
|
94
108
|
/**
|
|
95
109
|
* Membership check. With `cluster` the asset must be listed for THAT
|
|
96
110
|
* cluster; without it, listed for any cluster.
|
package/dist/index.js
CHANGED
|
@@ -559,6 +559,84 @@ function isReservedName(name) {
|
|
|
559
559
|
function isValidAgentName(name) {
|
|
560
560
|
return AGENT_NAME_REGEX.test(normalizeName(name));
|
|
561
561
|
}
|
|
562
|
+
var LOCK_ACCOUNT_SIZE = 269;
|
|
563
|
+
var LOCK_ACCOUNT_DISCRIMINATOR = new Uint8Array([8, 255, 36, 202, 210, 22, 57, 137]);
|
|
564
|
+
var LOCK_STATE_NAMES = ["created", "canceled", "in_progress", "submitted", "paid", "revoked", "disputing", "dispute_resolved", "dispute_closed"];
|
|
565
|
+
var LOCK_TERMINAL_STATES = ["canceled", "paid", "revoked", "dispute_resolved", "dispute_closed"];
|
|
566
|
+
var LockTerminalStates = {
|
|
567
|
+
CANCELED: "canceled",
|
|
568
|
+
PAID: "paid",
|
|
569
|
+
REVOKED: "revoked",
|
|
570
|
+
DISPUTE_RESOLVED: "dispute_resolved",
|
|
571
|
+
DISPUTE_CLOSED: "dispute_closed"
|
|
572
|
+
};
|
|
573
|
+
var ESCROW_RELEASE_METHODS = ["buyer_approved", "review_timeout"];
|
|
574
|
+
function isEscrowReleaseMethod(v) {
|
|
575
|
+
return typeof v === "string" && ESCROW_RELEASE_METHODS.includes(v);
|
|
576
|
+
}
|
|
577
|
+
var LockStates = {
|
|
578
|
+
CREATED: "created",
|
|
579
|
+
CANCELED: "canceled",
|
|
580
|
+
IN_PROGRESS: "in_progress",
|
|
581
|
+
SUBMITTED: "submitted",
|
|
582
|
+
PAID: "paid",
|
|
583
|
+
REVOKED: "revoked",
|
|
584
|
+
DISPUTING: "disputing",
|
|
585
|
+
DISPUTE_RESOLVED: "dispute_resolved",
|
|
586
|
+
DISPUTE_CLOSED: "dispute_closed"
|
|
587
|
+
};
|
|
588
|
+
var EscrowReleaseMethods = {
|
|
589
|
+
BUYER_APPROVED: "buyer_approved",
|
|
590
|
+
REVIEW_TIMEOUT: "review_timeout"
|
|
591
|
+
};
|
|
592
|
+
var NATIVE_SOL_MINT_BASE58 = "11111111111111111111111111111111";
|
|
593
|
+
function decodeLockAccount(data) {
|
|
594
|
+
if (data.length !== LOCK_ACCOUNT_SIZE) {
|
|
595
|
+
throw new Error(`decodeLockAccount: expected ${LOCK_ACCOUNT_SIZE} bytes, got ${data.length}`);
|
|
596
|
+
}
|
|
597
|
+
for (let i = 0; i < 8; i++) {
|
|
598
|
+
if (data[i] !== LOCK_ACCOUNT_DISCRIMINATOR[i]) {
|
|
599
|
+
throw new Error("decodeLockAccount: account discriminator is not Lock");
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
const stateByte = data[185];
|
|
603
|
+
const state = LOCK_STATE_NAMES[stateByte];
|
|
604
|
+
if (state === void 0) {
|
|
605
|
+
throw new Error(`decodeLockAccount: unknown LockState discriminant ${stateByte}`);
|
|
606
|
+
}
|
|
607
|
+
const mint = base.base58.encode(data.slice(113, 145));
|
|
608
|
+
return {
|
|
609
|
+
lockId: toHex(data.subarray(8, 40)),
|
|
610
|
+
version: data[40],
|
|
611
|
+
payer: base.base58.encode(data.slice(41, 73)),
|
|
612
|
+
payee: base.base58.encode(data.slice(73, 105)),
|
|
613
|
+
amount: readU64LE(data, 105),
|
|
614
|
+
mint,
|
|
615
|
+
isNative: mint === NATIVE_SOL_MINT_BASE58,
|
|
616
|
+
conditionHash: toHex(data.subarray(145, 177)),
|
|
617
|
+
expiry: readU64LE(data, 177),
|
|
618
|
+
state,
|
|
619
|
+
stateByte,
|
|
620
|
+
feeBpsAtLock: data[186] | data[187] << 8,
|
|
621
|
+
feeRecipientAtLock: base.base58.encode(data.slice(188, 220)),
|
|
622
|
+
workerStakeAtLock: readU64LE(data, 220),
|
|
623
|
+
operatorDisputeFeeAtLock: readU64LE(data, 228),
|
|
624
|
+
treasuryAtLock: base.base58.encode(data.slice(236, 268)),
|
|
625
|
+
bump: data[268]
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function toHex(bytes) {
|
|
629
|
+
let hex = "";
|
|
630
|
+
for (const b of bytes) hex += b.toString(16).padStart(2, "0");
|
|
631
|
+
return hex;
|
|
632
|
+
}
|
|
633
|
+
function readU64LE(buf, off) {
|
|
634
|
+
let v = 0n;
|
|
635
|
+
for (let i = 0; i < 8; i++) {
|
|
636
|
+
v |= BigInt(buf[off + i]) << BigInt(8 * i);
|
|
637
|
+
}
|
|
638
|
+
return v;
|
|
639
|
+
}
|
|
562
640
|
|
|
563
641
|
// src/assets.ts
|
|
564
642
|
var SOLANA_CLUSTER_IDS = {
|
|
@@ -621,6 +699,18 @@ function findAssetByAssetId(assetId) {
|
|
|
621
699
|
}
|
|
622
700
|
return null;
|
|
623
701
|
}
|
|
702
|
+
function findAssetMetaByMint(mint) {
|
|
703
|
+
if (mint === NATIVE_SOL_MINT_BASE58) return { assetId: null, symbol: "SOL", decimals: 9 };
|
|
704
|
+
for (const assets of Object.values(ASSET_WHITELIST)) {
|
|
705
|
+
for (const asset of assets) {
|
|
706
|
+
const splIdx = asset.asset_id.indexOf("/spl:");
|
|
707
|
+
if (splIdx !== -1 && asset.asset_id.slice(splIdx + "/spl:".length) === mint) {
|
|
708
|
+
return { assetId: asset.asset_id, symbol: asset.symbol ?? null, decimals: asset.decimals };
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return { assetId: null, symbol: null, decimals: null };
|
|
713
|
+
}
|
|
624
714
|
function isWhitelistedAssetId(assetId, cluster) {
|
|
625
715
|
const hit = findAssetByAssetId(assetId);
|
|
626
716
|
if (!hit) return false;
|
|
@@ -801,84 +891,6 @@ function buildResolveDisputeIxData(args, opts = {}) {
|
|
|
801
891
|
out.set(args.disputeId, 41);
|
|
802
892
|
return out;
|
|
803
893
|
}
|
|
804
|
-
var LOCK_ACCOUNT_SIZE = 269;
|
|
805
|
-
var LOCK_ACCOUNT_DISCRIMINATOR = new Uint8Array([8, 255, 36, 202, 210, 22, 57, 137]);
|
|
806
|
-
var LOCK_STATE_NAMES = ["created", "canceled", "in_progress", "submitted", "paid", "revoked", "disputing", "dispute_resolved", "dispute_closed"];
|
|
807
|
-
var LOCK_TERMINAL_STATES = ["canceled", "paid", "revoked", "dispute_resolved", "dispute_closed"];
|
|
808
|
-
var LockTerminalStates = {
|
|
809
|
-
CANCELED: "canceled",
|
|
810
|
-
PAID: "paid",
|
|
811
|
-
REVOKED: "revoked",
|
|
812
|
-
DISPUTE_RESOLVED: "dispute_resolved",
|
|
813
|
-
DISPUTE_CLOSED: "dispute_closed"
|
|
814
|
-
};
|
|
815
|
-
var ESCROW_RELEASE_METHODS = ["buyer_approved", "review_timeout"];
|
|
816
|
-
function isEscrowReleaseMethod(v) {
|
|
817
|
-
return typeof v === "string" && ESCROW_RELEASE_METHODS.includes(v);
|
|
818
|
-
}
|
|
819
|
-
var LockStates = {
|
|
820
|
-
CREATED: "created",
|
|
821
|
-
CANCELED: "canceled",
|
|
822
|
-
IN_PROGRESS: "in_progress",
|
|
823
|
-
SUBMITTED: "submitted",
|
|
824
|
-
PAID: "paid",
|
|
825
|
-
REVOKED: "revoked",
|
|
826
|
-
DISPUTING: "disputing",
|
|
827
|
-
DISPUTE_RESOLVED: "dispute_resolved",
|
|
828
|
-
DISPUTE_CLOSED: "dispute_closed"
|
|
829
|
-
};
|
|
830
|
-
var EscrowReleaseMethods = {
|
|
831
|
-
BUYER_APPROVED: "buyer_approved",
|
|
832
|
-
REVIEW_TIMEOUT: "review_timeout"
|
|
833
|
-
};
|
|
834
|
-
var NATIVE_SOL_MINT_BASE58 = "11111111111111111111111111111111";
|
|
835
|
-
function decodeLockAccount(data) {
|
|
836
|
-
if (data.length !== LOCK_ACCOUNT_SIZE) {
|
|
837
|
-
throw new Error(`decodeLockAccount: expected ${LOCK_ACCOUNT_SIZE} bytes, got ${data.length}`);
|
|
838
|
-
}
|
|
839
|
-
for (let i = 0; i < 8; i++) {
|
|
840
|
-
if (data[i] !== LOCK_ACCOUNT_DISCRIMINATOR[i]) {
|
|
841
|
-
throw new Error("decodeLockAccount: account discriminator is not Lock");
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
const stateByte = data[185];
|
|
845
|
-
const state = LOCK_STATE_NAMES[stateByte];
|
|
846
|
-
if (state === void 0) {
|
|
847
|
-
throw new Error(`decodeLockAccount: unknown LockState discriminant ${stateByte}`);
|
|
848
|
-
}
|
|
849
|
-
const mint = base.base58.encode(data.slice(113, 145));
|
|
850
|
-
return {
|
|
851
|
-
lockId: toHex(data.subarray(8, 40)),
|
|
852
|
-
version: data[40],
|
|
853
|
-
payer: base.base58.encode(data.slice(41, 73)),
|
|
854
|
-
payee: base.base58.encode(data.slice(73, 105)),
|
|
855
|
-
amount: readU64LE(data, 105),
|
|
856
|
-
mint,
|
|
857
|
-
isNative: mint === NATIVE_SOL_MINT_BASE58,
|
|
858
|
-
conditionHash: toHex(data.subarray(145, 177)),
|
|
859
|
-
expiry: readU64LE(data, 177),
|
|
860
|
-
state,
|
|
861
|
-
stateByte,
|
|
862
|
-
feeBpsAtLock: data[186] | data[187] << 8,
|
|
863
|
-
feeRecipientAtLock: base.base58.encode(data.slice(188, 220)),
|
|
864
|
-
workerStakeAtLock: readU64LE(data, 220),
|
|
865
|
-
operatorDisputeFeeAtLock: readU64LE(data, 228),
|
|
866
|
-
treasuryAtLock: base.base58.encode(data.slice(236, 268)),
|
|
867
|
-
bump: data[268]
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
function toHex(bytes) {
|
|
871
|
-
let hex = "";
|
|
872
|
-
for (const b of bytes) hex += b.toString(16).padStart(2, "0");
|
|
873
|
-
return hex;
|
|
874
|
-
}
|
|
875
|
-
function readU64LE(buf, off) {
|
|
876
|
-
let v = 0n;
|
|
877
|
-
for (let i = 0; i < 8; i++) {
|
|
878
|
-
v |= BigInt(buf[off + i]) << BigInt(8 * i);
|
|
879
|
-
}
|
|
880
|
-
return v;
|
|
881
|
-
}
|
|
882
894
|
var SPL_TOKEN_PROGRAM_ID = new web3_js.PublicKey(SPL_TOKEN_PROGRAM_ID_BASE58);
|
|
883
895
|
var ASSOCIATED_TOKEN_PROGRAM_ID = new web3_js.PublicKey(ASSOCIATED_TOKEN_PROGRAM_ID_BASE58);
|
|
884
896
|
var NATIVE_SOL_MINT = new web3_js.PublicKey(NATIVE_SOL_MINT_BASE58);
|
|
@@ -1314,6 +1326,7 @@ exports.deriveStakeVaultPda = deriveStakeVaultPda;
|
|
|
1314
1326
|
exports.expiresAt = expiresAt;
|
|
1315
1327
|
exports.fetchLockAccount = fetchLockAccount;
|
|
1316
1328
|
exports.findAssetByAssetId = findAssetByAssetId;
|
|
1329
|
+
exports.findAssetMetaByMint = findAssetMetaByMint;
|
|
1317
1330
|
exports.findFirstChainDivergence = findFirstChainDivergence;
|
|
1318
1331
|
exports.formatDid = formatDid;
|
|
1319
1332
|
exports.generateKeyPair = generateKeyPair;
|
package/dist/index.mjs
CHANGED
|
@@ -534,6 +534,84 @@ function isReservedName(name) {
|
|
|
534
534
|
function isValidAgentName(name) {
|
|
535
535
|
return AGENT_NAME_REGEX.test(normalizeName(name));
|
|
536
536
|
}
|
|
537
|
+
var LOCK_ACCOUNT_SIZE = 269;
|
|
538
|
+
var LOCK_ACCOUNT_DISCRIMINATOR = new Uint8Array([8, 255, 36, 202, 210, 22, 57, 137]);
|
|
539
|
+
var LOCK_STATE_NAMES = ["created", "canceled", "in_progress", "submitted", "paid", "revoked", "disputing", "dispute_resolved", "dispute_closed"];
|
|
540
|
+
var LOCK_TERMINAL_STATES = ["canceled", "paid", "revoked", "dispute_resolved", "dispute_closed"];
|
|
541
|
+
var LockTerminalStates = {
|
|
542
|
+
CANCELED: "canceled",
|
|
543
|
+
PAID: "paid",
|
|
544
|
+
REVOKED: "revoked",
|
|
545
|
+
DISPUTE_RESOLVED: "dispute_resolved",
|
|
546
|
+
DISPUTE_CLOSED: "dispute_closed"
|
|
547
|
+
};
|
|
548
|
+
var ESCROW_RELEASE_METHODS = ["buyer_approved", "review_timeout"];
|
|
549
|
+
function isEscrowReleaseMethod(v) {
|
|
550
|
+
return typeof v === "string" && ESCROW_RELEASE_METHODS.includes(v);
|
|
551
|
+
}
|
|
552
|
+
var LockStates = {
|
|
553
|
+
CREATED: "created",
|
|
554
|
+
CANCELED: "canceled",
|
|
555
|
+
IN_PROGRESS: "in_progress",
|
|
556
|
+
SUBMITTED: "submitted",
|
|
557
|
+
PAID: "paid",
|
|
558
|
+
REVOKED: "revoked",
|
|
559
|
+
DISPUTING: "disputing",
|
|
560
|
+
DISPUTE_RESOLVED: "dispute_resolved",
|
|
561
|
+
DISPUTE_CLOSED: "dispute_closed"
|
|
562
|
+
};
|
|
563
|
+
var EscrowReleaseMethods = {
|
|
564
|
+
BUYER_APPROVED: "buyer_approved",
|
|
565
|
+
REVIEW_TIMEOUT: "review_timeout"
|
|
566
|
+
};
|
|
567
|
+
var NATIVE_SOL_MINT_BASE58 = "11111111111111111111111111111111";
|
|
568
|
+
function decodeLockAccount(data) {
|
|
569
|
+
if (data.length !== LOCK_ACCOUNT_SIZE) {
|
|
570
|
+
throw new Error(`decodeLockAccount: expected ${LOCK_ACCOUNT_SIZE} bytes, got ${data.length}`);
|
|
571
|
+
}
|
|
572
|
+
for (let i = 0; i < 8; i++) {
|
|
573
|
+
if (data[i] !== LOCK_ACCOUNT_DISCRIMINATOR[i]) {
|
|
574
|
+
throw new Error("decodeLockAccount: account discriminator is not Lock");
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
const stateByte = data[185];
|
|
578
|
+
const state = LOCK_STATE_NAMES[stateByte];
|
|
579
|
+
if (state === void 0) {
|
|
580
|
+
throw new Error(`decodeLockAccount: unknown LockState discriminant ${stateByte}`);
|
|
581
|
+
}
|
|
582
|
+
const mint = base58.encode(data.slice(113, 145));
|
|
583
|
+
return {
|
|
584
|
+
lockId: toHex(data.subarray(8, 40)),
|
|
585
|
+
version: data[40],
|
|
586
|
+
payer: base58.encode(data.slice(41, 73)),
|
|
587
|
+
payee: base58.encode(data.slice(73, 105)),
|
|
588
|
+
amount: readU64LE(data, 105),
|
|
589
|
+
mint,
|
|
590
|
+
isNative: mint === NATIVE_SOL_MINT_BASE58,
|
|
591
|
+
conditionHash: toHex(data.subarray(145, 177)),
|
|
592
|
+
expiry: readU64LE(data, 177),
|
|
593
|
+
state,
|
|
594
|
+
stateByte,
|
|
595
|
+
feeBpsAtLock: data[186] | data[187] << 8,
|
|
596
|
+
feeRecipientAtLock: base58.encode(data.slice(188, 220)),
|
|
597
|
+
workerStakeAtLock: readU64LE(data, 220),
|
|
598
|
+
operatorDisputeFeeAtLock: readU64LE(data, 228),
|
|
599
|
+
treasuryAtLock: base58.encode(data.slice(236, 268)),
|
|
600
|
+
bump: data[268]
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
function toHex(bytes) {
|
|
604
|
+
let hex = "";
|
|
605
|
+
for (const b of bytes) hex += b.toString(16).padStart(2, "0");
|
|
606
|
+
return hex;
|
|
607
|
+
}
|
|
608
|
+
function readU64LE(buf, off) {
|
|
609
|
+
let v = 0n;
|
|
610
|
+
for (let i = 0; i < 8; i++) {
|
|
611
|
+
v |= BigInt(buf[off + i]) << BigInt(8 * i);
|
|
612
|
+
}
|
|
613
|
+
return v;
|
|
614
|
+
}
|
|
537
615
|
|
|
538
616
|
// src/assets.ts
|
|
539
617
|
var SOLANA_CLUSTER_IDS = {
|
|
@@ -596,6 +674,18 @@ function findAssetByAssetId(assetId) {
|
|
|
596
674
|
}
|
|
597
675
|
return null;
|
|
598
676
|
}
|
|
677
|
+
function findAssetMetaByMint(mint) {
|
|
678
|
+
if (mint === NATIVE_SOL_MINT_BASE58) return { assetId: null, symbol: "SOL", decimals: 9 };
|
|
679
|
+
for (const assets of Object.values(ASSET_WHITELIST)) {
|
|
680
|
+
for (const asset of assets) {
|
|
681
|
+
const splIdx = asset.asset_id.indexOf("/spl:");
|
|
682
|
+
if (splIdx !== -1 && asset.asset_id.slice(splIdx + "/spl:".length) === mint) {
|
|
683
|
+
return { assetId: asset.asset_id, symbol: asset.symbol ?? null, decimals: asset.decimals };
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return { assetId: null, symbol: null, decimals: null };
|
|
688
|
+
}
|
|
599
689
|
function isWhitelistedAssetId(assetId, cluster) {
|
|
600
690
|
const hit = findAssetByAssetId(assetId);
|
|
601
691
|
if (!hit) return false;
|
|
@@ -776,84 +866,6 @@ function buildResolveDisputeIxData(args, opts = {}) {
|
|
|
776
866
|
out.set(args.disputeId, 41);
|
|
777
867
|
return out;
|
|
778
868
|
}
|
|
779
|
-
var LOCK_ACCOUNT_SIZE = 269;
|
|
780
|
-
var LOCK_ACCOUNT_DISCRIMINATOR = new Uint8Array([8, 255, 36, 202, 210, 22, 57, 137]);
|
|
781
|
-
var LOCK_STATE_NAMES = ["created", "canceled", "in_progress", "submitted", "paid", "revoked", "disputing", "dispute_resolved", "dispute_closed"];
|
|
782
|
-
var LOCK_TERMINAL_STATES = ["canceled", "paid", "revoked", "dispute_resolved", "dispute_closed"];
|
|
783
|
-
var LockTerminalStates = {
|
|
784
|
-
CANCELED: "canceled",
|
|
785
|
-
PAID: "paid",
|
|
786
|
-
REVOKED: "revoked",
|
|
787
|
-
DISPUTE_RESOLVED: "dispute_resolved",
|
|
788
|
-
DISPUTE_CLOSED: "dispute_closed"
|
|
789
|
-
};
|
|
790
|
-
var ESCROW_RELEASE_METHODS = ["buyer_approved", "review_timeout"];
|
|
791
|
-
function isEscrowReleaseMethod(v) {
|
|
792
|
-
return typeof v === "string" && ESCROW_RELEASE_METHODS.includes(v);
|
|
793
|
-
}
|
|
794
|
-
var LockStates = {
|
|
795
|
-
CREATED: "created",
|
|
796
|
-
CANCELED: "canceled",
|
|
797
|
-
IN_PROGRESS: "in_progress",
|
|
798
|
-
SUBMITTED: "submitted",
|
|
799
|
-
PAID: "paid",
|
|
800
|
-
REVOKED: "revoked",
|
|
801
|
-
DISPUTING: "disputing",
|
|
802
|
-
DISPUTE_RESOLVED: "dispute_resolved",
|
|
803
|
-
DISPUTE_CLOSED: "dispute_closed"
|
|
804
|
-
};
|
|
805
|
-
var EscrowReleaseMethods = {
|
|
806
|
-
BUYER_APPROVED: "buyer_approved",
|
|
807
|
-
REVIEW_TIMEOUT: "review_timeout"
|
|
808
|
-
};
|
|
809
|
-
var NATIVE_SOL_MINT_BASE58 = "11111111111111111111111111111111";
|
|
810
|
-
function decodeLockAccount(data) {
|
|
811
|
-
if (data.length !== LOCK_ACCOUNT_SIZE) {
|
|
812
|
-
throw new Error(`decodeLockAccount: expected ${LOCK_ACCOUNT_SIZE} bytes, got ${data.length}`);
|
|
813
|
-
}
|
|
814
|
-
for (let i = 0; i < 8; i++) {
|
|
815
|
-
if (data[i] !== LOCK_ACCOUNT_DISCRIMINATOR[i]) {
|
|
816
|
-
throw new Error("decodeLockAccount: account discriminator is not Lock");
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
const stateByte = data[185];
|
|
820
|
-
const state = LOCK_STATE_NAMES[stateByte];
|
|
821
|
-
if (state === void 0) {
|
|
822
|
-
throw new Error(`decodeLockAccount: unknown LockState discriminant ${stateByte}`);
|
|
823
|
-
}
|
|
824
|
-
const mint = base58.encode(data.slice(113, 145));
|
|
825
|
-
return {
|
|
826
|
-
lockId: toHex(data.subarray(8, 40)),
|
|
827
|
-
version: data[40],
|
|
828
|
-
payer: base58.encode(data.slice(41, 73)),
|
|
829
|
-
payee: base58.encode(data.slice(73, 105)),
|
|
830
|
-
amount: readU64LE(data, 105),
|
|
831
|
-
mint,
|
|
832
|
-
isNative: mint === NATIVE_SOL_MINT_BASE58,
|
|
833
|
-
conditionHash: toHex(data.subarray(145, 177)),
|
|
834
|
-
expiry: readU64LE(data, 177),
|
|
835
|
-
state,
|
|
836
|
-
stateByte,
|
|
837
|
-
feeBpsAtLock: data[186] | data[187] << 8,
|
|
838
|
-
feeRecipientAtLock: base58.encode(data.slice(188, 220)),
|
|
839
|
-
workerStakeAtLock: readU64LE(data, 220),
|
|
840
|
-
operatorDisputeFeeAtLock: readU64LE(data, 228),
|
|
841
|
-
treasuryAtLock: base58.encode(data.slice(236, 268)),
|
|
842
|
-
bump: data[268]
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
|
-
function toHex(bytes) {
|
|
846
|
-
let hex = "";
|
|
847
|
-
for (const b of bytes) hex += b.toString(16).padStart(2, "0");
|
|
848
|
-
return hex;
|
|
849
|
-
}
|
|
850
|
-
function readU64LE(buf, off) {
|
|
851
|
-
let v = 0n;
|
|
852
|
-
for (let i = 0; i < 8; i++) {
|
|
853
|
-
v |= BigInt(buf[off + i]) << BigInt(8 * i);
|
|
854
|
-
}
|
|
855
|
-
return v;
|
|
856
|
-
}
|
|
857
869
|
var SPL_TOKEN_PROGRAM_ID = new PublicKey(SPL_TOKEN_PROGRAM_ID_BASE58);
|
|
858
870
|
var ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey(ASSOCIATED_TOKEN_PROGRAM_ID_BASE58);
|
|
859
871
|
var NATIVE_SOL_MINT = new PublicKey(NATIVE_SOL_MINT_BASE58);
|
|
@@ -1175,4 +1187,4 @@ var CliAuthTokenErrorCodes = {
|
|
|
1175
1187
|
REQUIRED: "AUTH_TOKEN_REQUIRED"
|
|
1176
1188
|
};
|
|
1177
1189
|
|
|
1178
|
-
export { AGENT_NAME_REGEX, AGENT_TAG_REGEX, ASSET_DECIMALS_MAX, ASSET_DECIMALS_MIN, ASSET_SYMBOL_MAX_LEN, ASSET_SYMBOL_MIN_LEN, ASSET_WHITELIST, ASSOCIATED_TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID_BASE58, BODY_TYPES, BodyTypes, CAIP19_REGEX, CLI_AUTH_TOKEN_ERROR_CODES, CLI_LOGIN_SESSION_STATES, CLI_LOGIN_SESSION_STORED_STATES, CREATE_LOCK_DISCRIMINATOR, CREATE_LOCK_NATIVE_DISCRIMINATOR, CURRENT_PROTOCOL_VERSION, CliAuthTokenErrorCodes, CliLoginSessionStates, DECIMAL_AMOUNT_REGEX, DECLINE_REASONS, DELEGATION_ACTIONS, DELEGATION_ACTIVE_STATES, DELEGATION_OFFER_REJECTION_CODES, DELEGATION_STATES, DEVNET_MINTS, DID_ARP_REGEX, DISCOVERY_SORTS, DelegationActions, DelegationOfferRejectionCodes, DelegationStates, DiscoverySorts, ED25519_SIG_PREFIX, ESCROW_PDA_SEEDS, ESCROW_PROGRAM_ID_BASE58, ESCROW_RELEASE_METHODS, EscrowReleaseMethods, HANDSHAKE_DECISIONS, HandshakeDecisions, INBOX_BLOCK_SCOPES, InboxBlockScopes, LIVE_RELATIONSHIP_STATE_NAMES, LOCK_ACCOUNT_DISCRIMINATOR, LOCK_ACCOUNT_SIZE, LOCK_STATE_NAMES, LOCK_TERMINAL_STATES, LockStates, LockTerminalStates, MAINNET_MINTS, MAX_CLOCK_SKEW_SECONDS, MAX_ENVELOPE_TTL_SECONDS, NATIVE_SOL_MINT, NATIVE_SOL_MINT_BASE58, NO_ARG_LIFECYCLE_INSTRUCTIONS, OWNER_SIGNING_METHODS, POST_COMMIT_ERROR_CODES, POST_COMMIT_ERROR_CODE_PREFIXES, PROTOCOL_VERSIONS, Purpose, READ_MODEL_STATUSES, RECEIPT_VERDICTS, RELATIONSHIP_STATE_NAMES, RESERVED_NAMES, ReadModelStatuses, ReceiptVerdicts, RelationshipStates, SCRYPT_PARAMS, SHA256_HEX_RE, SLIP44_SOLANA, SOLANA_CLUSTER_IDS, SPL_TOKEN_PROGRAM_ID, SPL_TOKEN_PROGRAM_ID_BASE58, SYSTEM_PROGRAM_ID_BASE58, TOKEN_2022_PROGRAM_ID_BASE58, WELL_KNOWN_ASSETS, WELL_KNOWN_ASSET_KEYS, WORK_LOG_STATES, WorkLogStates, base58btcDecode, base58btcEncode, buildAcceptLockIx, buildCancelLockIx, buildClaimExpiredWorkIx, buildClaimWorkPaymentIx, buildCloseDisputeIx, buildCreateLockIx, buildCreateLockIxData, buildLifecycleIxData, buildOpenDisputeIx, buildResolveDisputeIx, buildResolveDisputeIxData, buildSubmitWorkIx, bytes16ToDelegationId, canonicalBytes, canonicalJson, canonicalSha256Hex, decodeLockAccount, delegationIdToBytes16, deriveAta, deriveCollateralConfigPda, deriveConfigPda, deriveDelegationConditionHash, deriveDisputeResolutionPda, deriveEscrowPda, deriveEventAuthorityPda, deriveLockId, deriveLockPda, deriveOperatorAuthPda, deriveScryptKey, deriveStakeVaultPda, expiresAt, fetchLockAccount, findAssetByAssetId, findFirstChainDivergence, formatDid, generateKeyPair, getPublicKey2 as getPublicKey, instructionDiscriminator, isAssetIdentifier, isBodyType, isCliLoginSessionWireState, isDecimalAmountString, isDeclineReason, isDelegationAction, isDelegationState, isEscrowReleaseMethod, isHandshakeDecision, isPostCommitErrorCode, isReadModelStatus, isReceiptVerdict, isRelationshipState, isReservedName, isSha256Hex, isValidAgentName, isValidDid, isWhitelistedAssetId, isWorkLogState, normalizeName, parseCaip19SolanaAssetId, parseDid, pollUntil, resolveAsset, rfc3339, scryptPasswordProofSign, scryptPasswordProofVerify, senderNonce, serverEventHash, sign2 as sign, signChallenge, signEnvelope, signKeyLinkAttestation, signedMessageHash, uuidV4, verify2 as verify, verifyChallenge, verifyEnvelope, verifyKeyLinkAttestation };
|
|
1190
|
+
export { AGENT_NAME_REGEX, AGENT_TAG_REGEX, ASSET_DECIMALS_MAX, ASSET_DECIMALS_MIN, ASSET_SYMBOL_MAX_LEN, ASSET_SYMBOL_MIN_LEN, ASSET_WHITELIST, ASSOCIATED_TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID_BASE58, BODY_TYPES, BodyTypes, CAIP19_REGEX, CLI_AUTH_TOKEN_ERROR_CODES, CLI_LOGIN_SESSION_STATES, CLI_LOGIN_SESSION_STORED_STATES, CREATE_LOCK_DISCRIMINATOR, CREATE_LOCK_NATIVE_DISCRIMINATOR, CURRENT_PROTOCOL_VERSION, CliAuthTokenErrorCodes, CliLoginSessionStates, DECIMAL_AMOUNT_REGEX, DECLINE_REASONS, DELEGATION_ACTIONS, DELEGATION_ACTIVE_STATES, DELEGATION_OFFER_REJECTION_CODES, DELEGATION_STATES, DEVNET_MINTS, DID_ARP_REGEX, DISCOVERY_SORTS, DelegationActions, DelegationOfferRejectionCodes, DelegationStates, DiscoverySorts, ED25519_SIG_PREFIX, ESCROW_PDA_SEEDS, ESCROW_PROGRAM_ID_BASE58, ESCROW_RELEASE_METHODS, EscrowReleaseMethods, HANDSHAKE_DECISIONS, HandshakeDecisions, INBOX_BLOCK_SCOPES, InboxBlockScopes, LIVE_RELATIONSHIP_STATE_NAMES, LOCK_ACCOUNT_DISCRIMINATOR, LOCK_ACCOUNT_SIZE, LOCK_STATE_NAMES, LOCK_TERMINAL_STATES, LockStates, LockTerminalStates, MAINNET_MINTS, MAX_CLOCK_SKEW_SECONDS, MAX_ENVELOPE_TTL_SECONDS, NATIVE_SOL_MINT, NATIVE_SOL_MINT_BASE58, NO_ARG_LIFECYCLE_INSTRUCTIONS, OWNER_SIGNING_METHODS, POST_COMMIT_ERROR_CODES, POST_COMMIT_ERROR_CODE_PREFIXES, PROTOCOL_VERSIONS, Purpose, READ_MODEL_STATUSES, RECEIPT_VERDICTS, RELATIONSHIP_STATE_NAMES, RESERVED_NAMES, ReadModelStatuses, ReceiptVerdicts, RelationshipStates, SCRYPT_PARAMS, SHA256_HEX_RE, SLIP44_SOLANA, SOLANA_CLUSTER_IDS, SPL_TOKEN_PROGRAM_ID, SPL_TOKEN_PROGRAM_ID_BASE58, SYSTEM_PROGRAM_ID_BASE58, TOKEN_2022_PROGRAM_ID_BASE58, WELL_KNOWN_ASSETS, WELL_KNOWN_ASSET_KEYS, WORK_LOG_STATES, WorkLogStates, base58btcDecode, base58btcEncode, buildAcceptLockIx, buildCancelLockIx, buildClaimExpiredWorkIx, buildClaimWorkPaymentIx, buildCloseDisputeIx, buildCreateLockIx, buildCreateLockIxData, buildLifecycleIxData, buildOpenDisputeIx, buildResolveDisputeIx, buildResolveDisputeIxData, buildSubmitWorkIx, bytes16ToDelegationId, canonicalBytes, canonicalJson, canonicalSha256Hex, decodeLockAccount, delegationIdToBytes16, deriveAta, deriveCollateralConfigPda, deriveConfigPda, deriveDelegationConditionHash, deriveDisputeResolutionPda, deriveEscrowPda, deriveEventAuthorityPda, deriveLockId, deriveLockPda, deriveOperatorAuthPda, deriveScryptKey, deriveStakeVaultPda, expiresAt, fetchLockAccount, findAssetByAssetId, findAssetMetaByMint, findFirstChainDivergence, formatDid, generateKeyPair, getPublicKey2 as getPublicKey, instructionDiscriminator, isAssetIdentifier, isBodyType, isCliLoginSessionWireState, isDecimalAmountString, isDeclineReason, isDelegationAction, isDelegationState, isEscrowReleaseMethod, isHandshakeDecision, isPostCommitErrorCode, isReadModelStatus, isReceiptVerdict, isRelationshipState, isReservedName, isSha256Hex, isValidAgentName, isValidDid, isWhitelistedAssetId, isWorkLogState, normalizeName, parseCaip19SolanaAssetId, parseDid, pollUntil, resolveAsset, rfc3339, scryptPasswordProofSign, scryptPasswordProofVerify, senderNonce, serverEventHash, sign2 as sign, signChallenge, signEnvelope, signKeyLinkAttestation, signedMessageHash, uuidV4, verify2 as verify, verifyChallenge, verifyEnvelope, verifyKeyLinkAttestation };
|
package/dist/types/agent.d.ts
CHANGED
|
@@ -144,6 +144,58 @@ export interface AgentReputation {
|
|
|
144
144
|
computed: boolean;
|
|
145
145
|
lastComputedAt?: string | null;
|
|
146
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Settled on-chain volume for ONE asset, from one role (earned as payee /
|
|
149
|
+
* paid as payer). Amounts are exact integer base-units (string, never a
|
|
150
|
+
* float); `amountDecimal` is the human form, present only when the asset's
|
|
151
|
+
* decimals are known. `mint` is always the unambiguous identifier — `assetId`
|
|
152
|
+
* /`symbol`/`decimals` are best-effort labels (null for an unrecognised mint).
|
|
153
|
+
*/
|
|
154
|
+
export interface AssetVolume {
|
|
155
|
+
mint: string;
|
|
156
|
+
assetId: string | null;
|
|
157
|
+
symbol: string | null;
|
|
158
|
+
decimals: number | null;
|
|
159
|
+
amountBaseUnits: string;
|
|
160
|
+
amountDecimal: string | null;
|
|
161
|
+
lockCount: number;
|
|
162
|
+
}
|
|
163
|
+
/** Per-agent settled-escrow volume, split by role and bucketed by asset. */
|
|
164
|
+
export interface AgentSettlementVolume {
|
|
165
|
+
/** Received as payee (the worker side) — the headline trust signal. */
|
|
166
|
+
earnedByAsset: AssetVolume[];
|
|
167
|
+
/** Spent as payer (the buyer side). */
|
|
168
|
+
paidByAsset: AssetVolume[];
|
|
169
|
+
/** Span of settled activity (a Paid lock's last on-chain transition). */
|
|
170
|
+
firstSettledAt: string | null;
|
|
171
|
+
lastSettledAt: string | null;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Derived ratios from the reputation counters. Each is `null` when its
|
|
175
|
+
* denominator is 0 (no basis to compute), never a misleading 0.
|
|
176
|
+
*/
|
|
177
|
+
export interface AgentStatsRates {
|
|
178
|
+
/** completed / (completed + failed) delegations. */
|
|
179
|
+
completionRate: number | null;
|
|
180
|
+
/** disputed / onchainCycles — share of terminal cycles that hit a dispute. */
|
|
181
|
+
disputeRate: number | null;
|
|
182
|
+
/** disputesAdverse / disputed — share of disputes ruled against. */
|
|
183
|
+
adverseDisputeRate: number | null;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Quantitative per-agent stats — `GET /v1/agents/:did/stats`. PUBLIC, no-auth.
|
|
187
|
+
* Counters/scores reuse the materialised reputation row (single source of truth
|
|
188
|
+
* with `/reputation`); rates are derived; volume is aggregated live from the
|
|
189
|
+
* on-chain escrow-lock mirror (cached). `computed: false` ⇒ no settled cycle yet.
|
|
190
|
+
*/
|
|
191
|
+
export interface AgentStats {
|
|
192
|
+
did: string;
|
|
193
|
+
computed: boolean;
|
|
194
|
+
counters: ReputationCounters;
|
|
195
|
+
scores: ReputationScores;
|
|
196
|
+
rates: AgentStatsRates;
|
|
197
|
+
volume: AgentSettlementVolume;
|
|
198
|
+
}
|
|
147
199
|
/**
|
|
148
200
|
* Agent capability-tag charset — lowercase alphanumeric + dash +
|
|
149
201
|
* underscore, 1-40 chars. Single source of truth for the server's
|
package/dist/types/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export { INBOX_BLOCK_SCOPES, InboxBlockScopes } from './inbox';
|
|
|
17
17
|
export type { CliSessionCreated, CliTokenIssued, CliWhoami, MyAgentSummary, CliLoginSessionStoredState, CliLoginSessionWireState, } from './cli-auth';
|
|
18
18
|
export { CLI_LOGIN_SESSION_STORED_STATES, CLI_LOGIN_SESSION_STATES, CliLoginSessionStates, isCliLoginSessionWireState } from './cli-auth';
|
|
19
19
|
export type { AssetIdentifierWire, DelegationPublic, DisputeResolutionPublic, ReceiptPublic, RelationshipPublic, WorkLogPublic, EventPublic, IngestResult, SenderSequenceResponse, InboxUnblockResult, ListRelationshipsQuery, ListInboxQuery, ListEventsQuery, ListDelegationsQuery, ListWorkLogsQuery, ListReceiptsQuery, } from './read-model';
|
|
20
|
-
export type { AcceptPrefs, AcceptCurrency, AgentRegisteredResponse, AgentPublic, UpdateAgentBody, RegisterAgentRequest, ChallengeResponse, ReputationScores, ReputationCounters, AgentReputation, } from './agent';
|
|
20
|
+
export type { AcceptPrefs, AcceptCurrency, AgentRegisteredResponse, AgentPublic, UpdateAgentBody, RegisterAgentRequest, ChallengeResponse, ReputationScores, ReputationCounters, AgentReputation, AssetVolume, AgentSettlementVolume, AgentStatsRates, AgentStats, } from './agent';
|
|
21
21
|
export { AGENT_TAG_REGEX, AGENT_NAME_REGEX, RESERVED_NAMES, isReservedName, isValidAgentName, normalizeName } from './agent';
|
|
22
22
|
export type { OwnerSigningMethod, KeyLinkPayload, ScryptPasswordAttestation } from './identity';
|
|
23
23
|
export { SCRYPT_PARAMS, OWNER_SIGNING_METHODS } from './identity';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyanon-arp/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
4
4
|
"description": "TypeScript SDK for the Agent Relationship Protocol — canonical JSON, Ed25519 envelope sign/verify, did:arp identity, scrypt key attestation, chain-audit helpers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|