@brainai/satp-client 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -22
- package/examples/runtime-policy-adapter.js +33 -13
- package/package.json +6 -3
- package/src/borsh-reader.d.ts +5 -0
- package/src/borsh-reader.js +25 -11
- package/src/index.d.ts +210 -1
- package/src/index.js +23 -0
- package/src/runtime-policy-adapter.js +293 -0
- package/src/signer-policy.js +210 -0
- package/src/v3-idl-discriminators.js +17 -0
- package/src/v3-pda.d.ts +26 -0
- package/src/v3-pda.js +57 -6
- package/src/v3-sdk.d.ts +85 -4
- package/src/v3-sdk.js +379 -13
package/src/v3-pda.js
CHANGED
|
@@ -6,15 +6,33 @@ const crypto = require('crypto');
|
|
|
6
6
|
// ═══════════════════════════════════════════════════
|
|
7
7
|
|
|
8
8
|
const V3_DEVNET_PROGRAM_IDS = {
|
|
9
|
+
IDENTITY: new PublicKey('7qmfg4CgiXVDZGBeUkSkMsacKjCRty2xEAugPK4nfvZQ'),
|
|
10
|
+
REVIEWS: new PublicKey('3yVFrWCpBnQdWNqmiCG9EpoZq7WYeQ421Gx5sUh41Kwk'),
|
|
11
|
+
REPUTATION: new PublicKey('CtmZ1fHaypt3R6wbeiGawiRnjzRK9T8jsECk9mET9AK9'),
|
|
12
|
+
ATTESTATIONS: new PublicKey('55aS2y5Lhe427iW4cgo2nmZPrxwH3F7BWkw6MnoEm4zw'),
|
|
13
|
+
VALIDATION: new PublicKey('DLB76DzAFY8KNuvnP79BZW3cehGreEQTeGDvFCNd2Ekj'),
|
|
14
|
+
ESCROW: new PublicKey('B1Se8SPx7GLUisa4LYeXY1tDZy5TviJrsV2yMLgqUXmg'),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Mainnet registry source: Anchor.toml [programs.mainnet], checked by
|
|
18
|
+
// scripts/verify-v3-program-sources.mjs and the D1 authority packet.
|
|
19
|
+
// docs/mainnet-authority-decision-packet-6c8a5545.md remains the owner-gating
|
|
20
|
+
// packet for deploy/key/publish actions. Keep V3 separate from legacy V2
|
|
21
|
+
// MAINNET_PROGRAM_IDS in constants.js; do not fall back to V2 program IDs.
|
|
22
|
+
const V3_MAINNET_PROGRAM_IDS = {
|
|
9
23
|
IDENTITY: new PublicKey('GTppU4E44BqXTQgbqMZ68ozFzhP1TLty3EGnzzjtNZfG'),
|
|
10
24
|
REVIEWS: new PublicKey('r9XX4frcqxxAZ6Au9V5PA3EAxs1zoNckqLLmoSRcNr4'),
|
|
11
25
|
REPUTATION: new PublicKey('2Lz7KzMvKdrGeAuS8WPHu7jK2yScrnKVgacpYVEuDjkJ'),
|
|
12
26
|
ATTESTATIONS: new PublicKey('6Xd1dAQJPvQRJ4Ntr6LtPTjDjPUZ8nfnmYLZaZ2DtrdD'),
|
|
13
27
|
VALIDATION: new PublicKey('6rYRiCYidJYV7QvKrzKGgNu4oMh6BAvynked69R7xMbV'),
|
|
14
|
-
ESCROW: new PublicKey('
|
|
28
|
+
ESCROW: new PublicKey('HXCUWKR2NvRcZ7rNAJHwPcH6QAAWaLR4bRFbfyuDND6C'),
|
|
15
29
|
};
|
|
30
|
+
const SPL_TOKEN_PROGRAM_ID = new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
|
|
31
|
+
const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
16
32
|
|
|
17
|
-
const
|
|
33
|
+
const V3_DEVNET_TOKEN_MINTS = {
|
|
34
|
+
USDC: new PublicKey('4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU'),
|
|
35
|
+
};
|
|
18
36
|
|
|
19
37
|
// ═══════════════════════════════════════════════════
|
|
20
38
|
// V3 PDA Seeds — must match on-chain programs
|
|
@@ -41,10 +59,7 @@ function getV3ProgramIds(network = 'devnet') {
|
|
|
41
59
|
if (network !== 'devnet' && network !== 'mainnet') {
|
|
42
60
|
throw new Error('Invalid network: expected devnet or mainnet');
|
|
43
61
|
}
|
|
44
|
-
|
|
45
|
-
throw new Error('SATP V3 mainnet program IDs are not configured; use devnet or provide an approved mainnet decision packet before enabling mainnet');
|
|
46
|
-
}
|
|
47
|
-
return V3_DEVNET_PROGRAM_IDS;
|
|
62
|
+
return network === 'mainnet' ? V3_MAINNET_PROGRAM_IDS : V3_DEVNET_PROGRAM_IDS;
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
// ═══════════════════════════════════════════════════
|
|
@@ -256,10 +271,44 @@ function getV3EscrowPDA(client, descriptionHash, nonce, network = 'devnet') {
|
|
|
256
271
|
);
|
|
257
272
|
}
|
|
258
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Derive the canonical associated token account address.
|
|
276
|
+
* Seeds: [owner, SPL Token program, mint]
|
|
277
|
+
* @param {PublicKey|string} owner
|
|
278
|
+
* @param {PublicKey|string} mint
|
|
279
|
+
* @returns {[PublicKey, number]}
|
|
280
|
+
*/
|
|
281
|
+
function getAssociatedTokenAddress(owner, mint) {
|
|
282
|
+
const ownerKey = new PublicKey(owner);
|
|
283
|
+
const mintKey = new PublicKey(mint);
|
|
284
|
+
return PublicKey.findProgramAddressSync(
|
|
285
|
+
[ownerKey.toBuffer(), SPL_TOKEN_PROGRAM_ID.toBuffer(), mintKey.toBuffer()],
|
|
286
|
+
ASSOCIATED_TOKEN_PROGRAM_ID
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Derive the escrow PDA and its SPL vault ATA for a mint.
|
|
292
|
+
* @param {PublicKey|string} client
|
|
293
|
+
* @param {Buffer} descriptionHash
|
|
294
|
+
* @param {number|bigint} nonce
|
|
295
|
+
* @param {PublicKey|string} mint
|
|
296
|
+
* @param {'mainnet'|'devnet'} network
|
|
297
|
+
* @returns {{ escrowPDA: PublicKey, escrowBump: number, vaultATA: PublicKey, vaultBump: number }}
|
|
298
|
+
*/
|
|
299
|
+
function getV3EscrowVaultATA(client, descriptionHash, nonce, mint, network = 'devnet') {
|
|
300
|
+
const [escrowPDA, escrowBump] = getV3EscrowPDA(client, descriptionHash, nonce, network);
|
|
301
|
+
const [vaultATA, vaultBump] = getAssociatedTokenAddress(escrowPDA, mint);
|
|
302
|
+
return { escrowPDA, escrowBump, vaultATA, vaultBump };
|
|
303
|
+
}
|
|
304
|
+
|
|
259
305
|
module.exports = {
|
|
260
306
|
// Program IDs
|
|
261
307
|
V3_DEVNET_PROGRAM_IDS,
|
|
262
308
|
V3_MAINNET_PROGRAM_IDS,
|
|
309
|
+
V3_DEVNET_TOKEN_MINTS,
|
|
310
|
+
SPL_TOKEN_PROGRAM_ID,
|
|
311
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
263
312
|
getV3ProgramIds,
|
|
264
313
|
V3_SEEDS,
|
|
265
314
|
|
|
@@ -278,4 +327,6 @@ module.exports = {
|
|
|
278
327
|
getV3ReviewCounterPDA,
|
|
279
328
|
getV3AttestationPDA,
|
|
280
329
|
getV3EscrowPDA,
|
|
330
|
+
getAssociatedTokenAddress,
|
|
331
|
+
getV3EscrowVaultATA,
|
|
281
332
|
};
|
package/src/v3-sdk.d.ts
CHANGED
|
@@ -124,16 +124,41 @@ export interface UpdateReviewFields {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
export type EscrowStatus = 'Active' | 'WorkSubmitted' | 'Released' | 'Cancelled' | 'Disputed' | 'Resolved';
|
|
127
|
+
export type EscrowCurrency = 'SOL' | 'USDC';
|
|
127
128
|
|
|
128
129
|
export interface CreateEscrowOpts {
|
|
130
|
+
currency?: EscrowCurrency;
|
|
129
131
|
minVerificationLevel?: number;
|
|
130
132
|
requireBorn?: boolean;
|
|
131
133
|
arbiter?: PublicKey | string;
|
|
134
|
+
mint?: PublicKey | string;
|
|
135
|
+
tokenDecimals?: number;
|
|
136
|
+
createVaultAta?: boolean;
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
export interface CreateEscrowResult extends TransactionResult {
|
|
135
140
|
escrowPDA: PublicKey;
|
|
136
141
|
descriptionHash: Buffer;
|
|
142
|
+
currency?: EscrowCurrency;
|
|
143
|
+
mint?: PublicKey;
|
|
144
|
+
clientTokenAccount?: PublicKey;
|
|
145
|
+
vaultTokenAccount?: PublicKey;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface UsdcEscrowAccountOpts {
|
|
149
|
+
currency?: 'USDC';
|
|
150
|
+
mint?: PublicKey | string;
|
|
151
|
+
tokenDecimals?: number;
|
|
152
|
+
createVaultAta?: boolean;
|
|
153
|
+
createAgentAta?: boolean;
|
|
154
|
+
createClientAta?: boolean;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface UsdcEscrowResult extends TransactionResult {
|
|
158
|
+
mint: PublicKey;
|
|
159
|
+
vaultTokenAccount: PublicKey;
|
|
160
|
+
agentTokenAccount?: PublicKey;
|
|
161
|
+
clientTokenAccount?: PublicKey;
|
|
137
162
|
}
|
|
138
163
|
|
|
139
164
|
export interface SubmitWorkResult extends TransactionResult {
|
|
@@ -161,6 +186,11 @@ export interface V3Escrow {
|
|
|
161
186
|
descriptionHash: string;
|
|
162
187
|
deadline: number;
|
|
163
188
|
nonce: number;
|
|
189
|
+
currency: EscrowCurrency | string;
|
|
190
|
+
currencyCode: number;
|
|
191
|
+
tokenMint: string | null;
|
|
192
|
+
tokenVault: string | null;
|
|
193
|
+
tokenDecimals: number | null;
|
|
164
194
|
status: EscrowStatus;
|
|
165
195
|
statusCode: number;
|
|
166
196
|
minVerificationLevel: number;
|
|
@@ -413,6 +443,18 @@ export class SATPV3SDK {
|
|
|
413
443
|
opts?: CreateEscrowOpts
|
|
414
444
|
): Promise<CreateEscrowResult>;
|
|
415
445
|
|
|
446
|
+
/** Build createEscrow transaction for USDC/SPL token escrow. */
|
|
447
|
+
buildCreateUsdcEscrow(
|
|
448
|
+
client: PublicKey | string,
|
|
449
|
+
agentWallet: PublicKey | string,
|
|
450
|
+
agentId: string,
|
|
451
|
+
amount: number,
|
|
452
|
+
descriptionOrHash: string | Buffer,
|
|
453
|
+
deadline: number,
|
|
454
|
+
nonce?: number,
|
|
455
|
+
opts?: UsdcEscrowAccountOpts & Pick<CreateEscrowOpts, 'minVerificationLevel' | 'requireBorn' | 'arbiter'>
|
|
456
|
+
): Promise<CreateEscrowResult>;
|
|
457
|
+
|
|
416
458
|
/** Build submitWork transaction (agent submits work proof). */
|
|
417
459
|
buildSubmitWork(
|
|
418
460
|
agent: PublicKey | string,
|
|
@@ -424,23 +466,50 @@ export class SATPV3SDK {
|
|
|
424
466
|
buildEscrowRelease(
|
|
425
467
|
client: PublicKey | string,
|
|
426
468
|
agent: PublicKey | string,
|
|
427
|
-
escrowPDA: PublicKey | string
|
|
469
|
+
escrowPDA: PublicKey | string,
|
|
470
|
+
opts?: UsdcEscrowAccountOpts
|
|
428
471
|
): Promise<TransactionResult>;
|
|
429
472
|
|
|
473
|
+
/** Build release transaction for USDC/SPL escrow funds. */
|
|
474
|
+
buildUsdcEscrowRelease(
|
|
475
|
+
client: PublicKey | string,
|
|
476
|
+
agent: PublicKey | string,
|
|
477
|
+
escrowPDA: PublicKey | string,
|
|
478
|
+
opts?: UsdcEscrowAccountOpts
|
|
479
|
+
): Promise<UsdcEscrowResult>;
|
|
480
|
+
|
|
430
481
|
/** Build partialRelease transaction (milestone payment). */
|
|
431
482
|
buildPartialRelease(
|
|
432
483
|
client: PublicKey | string,
|
|
433
484
|
agent: PublicKey | string,
|
|
434
485
|
escrowPDA: PublicKey | string,
|
|
435
|
-
amount: number
|
|
486
|
+
amount: number,
|
|
487
|
+
opts?: UsdcEscrowAccountOpts
|
|
436
488
|
): Promise<TransactionResult>;
|
|
437
489
|
|
|
490
|
+
/** Build partial release transaction for USDC/SPL escrow funds. */
|
|
491
|
+
buildPartialUsdcEscrowRelease(
|
|
492
|
+
client: PublicKey | string,
|
|
493
|
+
agent: PublicKey | string,
|
|
494
|
+
escrowPDA: PublicKey | string,
|
|
495
|
+
amount: number,
|
|
496
|
+
opts?: UsdcEscrowAccountOpts
|
|
497
|
+
): Promise<UsdcEscrowResult>;
|
|
498
|
+
|
|
438
499
|
/** Build cancel transaction (client cancels after deadline). */
|
|
439
500
|
buildCancelEscrow(
|
|
440
501
|
client: PublicKey | string,
|
|
441
|
-
escrowPDA: PublicKey | string
|
|
502
|
+
escrowPDA: PublicKey | string,
|
|
503
|
+
opts?: UsdcEscrowAccountOpts
|
|
442
504
|
): Promise<TransactionResult>;
|
|
443
505
|
|
|
506
|
+
/** Build cancel transaction for USDC/SPL escrow refund. */
|
|
507
|
+
buildUsdcCancelEscrow(
|
|
508
|
+
client: PublicKey | string,
|
|
509
|
+
escrowPDA: PublicKey | string,
|
|
510
|
+
opts?: UsdcEscrowAccountOpts
|
|
511
|
+
): Promise<UsdcEscrowResult>;
|
|
512
|
+
|
|
444
513
|
/** Build raiseDispute transaction (either client or agent). */
|
|
445
514
|
buildRaiseDispute(
|
|
446
515
|
signer: PublicKey | string,
|
|
@@ -455,9 +524,21 @@ export class SATPV3SDK {
|
|
|
455
524
|
clientWallet: PublicKey | string,
|
|
456
525
|
escrowPDA: PublicKey | string,
|
|
457
526
|
agentAmount: number,
|
|
458
|
-
clientAmount: number
|
|
527
|
+
clientAmount: number,
|
|
528
|
+
opts?: UsdcEscrowAccountOpts
|
|
459
529
|
): Promise<TransactionResult>;
|
|
460
530
|
|
|
531
|
+
/** Build resolveDispute transaction for USDC/SPL escrow funds. */
|
|
532
|
+
buildUsdcResolveDispute(
|
|
533
|
+
arbiter: PublicKey | string,
|
|
534
|
+
agent: PublicKey | string,
|
|
535
|
+
clientWallet: PublicKey | string,
|
|
536
|
+
escrowPDA: PublicKey | string,
|
|
537
|
+
agentAmount: number,
|
|
538
|
+
clientAmount: number,
|
|
539
|
+
opts?: UsdcEscrowAccountOpts
|
|
540
|
+
): Promise<UsdcEscrowResult>;
|
|
541
|
+
|
|
461
542
|
/** Build extendDeadline transaction (client extends escrow deadline). */
|
|
462
543
|
buildExtendDeadline(
|
|
463
544
|
client: PublicKey | string,
|