@dynamic-labs-wallet/svm 1.1.62 → 1.1.64
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/index.cjs +227 -9
- package/index.esm.js +228 -10
- package/package.json +4 -4
- package/src/svm/client.d.ts +26 -5
- package/src/svm/client.d.ts.map +1 -1
- package/src/svm/confidentialCheck.d.ts +27 -0
- package/src/svm/confidentialCheck.d.ts.map +1 -0
package/index.cjs
CHANGED
|
@@ -15,6 +15,143 @@ function _extends() {
|
|
|
15
15
|
return _extends.apply(this, arguments);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const TOKEN_2022 = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
|
|
19
|
+
const ASSOCIATED_TOKEN = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
|
|
20
|
+
const SYSTEM = '11111111111111111111111111111111';
|
|
21
|
+
const ZK_ELGAMAL_PROOF = 'ZkE1Gama1Proof11111111111111111111111111111';
|
|
22
|
+
const COMPUTE_BUDGET = 'ComputeBudget111111111111111111111111111111';
|
|
23
|
+
const ALLOWED_PROGRAMS = new Set([
|
|
24
|
+
TOKEN_2022,
|
|
25
|
+
ASSOCIATED_TOKEN,
|
|
26
|
+
SYSTEM,
|
|
27
|
+
ZK_ELGAMAL_PROOF,
|
|
28
|
+
COMPUTE_BUDGET
|
|
29
|
+
]);
|
|
30
|
+
// Helper instructions the planner may emit alongside the confidential one.
|
|
31
|
+
const COMPUTE_SET_UNIT_LIMIT = 2;
|
|
32
|
+
const COMPUTE_SET_UNIT_PRICE = 3;
|
|
33
|
+
const ATA_CREATE = 0;
|
|
34
|
+
const ATA_CREATE_IDEMPOTENT = 1;
|
|
35
|
+
const SYSTEM_CREATE_ACCOUNT = 0;
|
|
36
|
+
const TOKEN_REALLOCATE = 29;
|
|
37
|
+
// Token-2022 ConfidentialTransferExtension (27) sub-instruction per operation.
|
|
38
|
+
const CONFIDENTIAL_EXTENSION = 27;
|
|
39
|
+
const SUB_INSTRUCTION = {
|
|
40
|
+
configureAccount: 2,
|
|
41
|
+
deposit: 5,
|
|
42
|
+
withdraw: 6,
|
|
43
|
+
transfer: 7,
|
|
44
|
+
applyPendingBalance: 8
|
|
45
|
+
};
|
|
46
|
+
const V1_PREFIX = 0x81;
|
|
47
|
+
const refuse = (reason)=>{
|
|
48
|
+
throw new Error(`Refusing to sign confidential transaction: ${reason}`);
|
|
49
|
+
};
|
|
50
|
+
/** Message bytes an MPC signer signs: a v1 wire is message || 64B signature slots. */ const confidentialSignedMessageBytes = (wire, numRequiredSignatures)=>wire.slice(0, wire.length - numRequiredSignatures * web3_js.SIGNATURE_LENGTH_IN_BYTES);
|
|
51
|
+
/** Insert the wallet signature into the sole v1 signature slot (signer index 0). */ const injectConfidentialSignature = (wire, signature)=>Uint8Array.from([
|
|
52
|
+
...wire.slice(0, wire.length - web3_js.SIGNATURE_LENGTH_IN_BYTES),
|
|
53
|
+
...signature
|
|
54
|
+
]);
|
|
55
|
+
const decodeV1Message = (encoded, solanaAddress)=>{
|
|
56
|
+
const wire = new Uint8Array(Buffer.from(encoded, 'base64'));
|
|
57
|
+
if (wire[0] !== V1_PREFIX) {
|
|
58
|
+
refuse('not a version 1 transaction');
|
|
59
|
+
}
|
|
60
|
+
let message;
|
|
61
|
+
try {
|
|
62
|
+
message = web3_js.VersionedTransaction.deserialize(wire).message;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return refuse('malformed transaction');
|
|
65
|
+
}
|
|
66
|
+
if (message.version !== 1) {
|
|
67
|
+
refuse('not a version 1 transaction');
|
|
68
|
+
}
|
|
69
|
+
if (message.header.numRequiredSignatures !== 1) {
|
|
70
|
+
refuse('unexpected extra signers');
|
|
71
|
+
}
|
|
72
|
+
const keys = message.staticAccountKeys.map((key)=>key.toBase58());
|
|
73
|
+
if (keys[0] !== solanaAddress) {
|
|
74
|
+
refuse('the wallet is not the fee payer');
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
message,
|
|
78
|
+
keys
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
const isAllowedHelperInstruction = (program, data)=>{
|
|
82
|
+
switch(program){
|
|
83
|
+
case COMPUTE_BUDGET:
|
|
84
|
+
return data[0] === COMPUTE_SET_UNIT_LIMIT || data[0] === COMPUTE_SET_UNIT_PRICE;
|
|
85
|
+
case ASSOCIATED_TOKEN:
|
|
86
|
+
return data.length === 0 || data[0] === ATA_CREATE || data[0] === ATA_CREATE_IDEMPOTENT;
|
|
87
|
+
case SYSTEM:
|
|
88
|
+
return data.length >= 4 && Buffer.from(data).readUInt32LE(0) === SYSTEM_CREATE_ACCOUNT;
|
|
89
|
+
case TOKEN_2022:
|
|
90
|
+
return data[0] === TOKEN_REALLOCATE;
|
|
91
|
+
default:
|
|
92
|
+
return program === ZK_ELGAMAL_PROOF;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const checkOperationInstruction = (data, accounts, params)=>{
|
|
96
|
+
const { operation, mint, tokenAccount, destinationTokenAccount, amount, decimals } = params;
|
|
97
|
+
if (data[1] !== SUB_INSTRUCTION[operation]) {
|
|
98
|
+
refuse(`confidential instruction ${data[1]} does not match ${operation}`);
|
|
99
|
+
}
|
|
100
|
+
if (accounts[0] !== tokenAccount) {
|
|
101
|
+
refuse('instruction targets an unexpected token account');
|
|
102
|
+
}
|
|
103
|
+
if (operation !== 'applyPendingBalance' && accounts[1] !== mint) {
|
|
104
|
+
refuse('instruction uses an unexpected mint');
|
|
105
|
+
}
|
|
106
|
+
if (operation === 'transfer' && (!destinationTokenAccount || accounts[2] !== destinationTokenAccount)) {
|
|
107
|
+
refuse('transfer destination does not match the request');
|
|
108
|
+
}
|
|
109
|
+
if (operation !== 'deposit' && operation !== 'withdraw') {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// Confidential amount layout: [27, sub, amount u64 LE, decimals u8, ...].
|
|
113
|
+
const bytes = Buffer.from(data);
|
|
114
|
+
if (amount === undefined || bytes.length < 11 || bytes.readBigUInt64LE(2).toString() !== amount) {
|
|
115
|
+
refuse(`${operation} amount does not match the request`);
|
|
116
|
+
}
|
|
117
|
+
if (decimals === undefined || bytes[10] !== decimals) {
|
|
118
|
+
refuse(`${operation} decimals do not match the request`);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Structural check on the enclave-built confidential transaction before the
|
|
123
|
+
* client share joins the MPC room: must be one v1 message, the wallet must be
|
|
124
|
+
* fee payer and only signer, only expected programs and instruction kinds may
|
|
125
|
+
* appear, and the confidential instruction must match the requested
|
|
126
|
+
* operation, mint, token accounts and amounts. The enclave's
|
|
127
|
+
* `transactionsTag` binds the build; this only guards against a bad build
|
|
128
|
+
* reaching the ceremony.
|
|
129
|
+
*/ const checkConfidentialTransactions = (params)=>{
|
|
130
|
+
if (params.serializedTransactions.length !== 1) {
|
|
131
|
+
refuse('expected exactly one version 1 transaction');
|
|
132
|
+
}
|
|
133
|
+
const { message, keys } = decodeV1Message(params.serializedTransactions[0], params.solanaAddress);
|
|
134
|
+
let sawOperation = false;
|
|
135
|
+
for (const ix of message.compiledInstructions){
|
|
136
|
+
const program = keys[ix.programIdIndex];
|
|
137
|
+
if (!program || !ALLOWED_PROGRAMS.has(program)) {
|
|
138
|
+
refuse(`unexpected program ${program}`);
|
|
139
|
+
}
|
|
140
|
+
if (program === TOKEN_2022 && ix.data[0] === CONFIDENTIAL_EXTENSION) {
|
|
141
|
+
if (sawOperation) {
|
|
142
|
+
refuse('more than one confidential instruction');
|
|
143
|
+
}
|
|
144
|
+
checkOperationInstruction(ix.data, ix.accountKeyIndexes.map((i)=>keys[i]), params);
|
|
145
|
+
sawOperation = true;
|
|
146
|
+
} else if (!isAllowedHelperInstruction(program, ix.data)) {
|
|
147
|
+
refuse(`unexpected instruction ${ix.data[0]} for program ${program}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!sawOperation) {
|
|
151
|
+
refuse(`no confidential instruction for ${params.operation}`);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
18
155
|
class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
19
156
|
/**
|
|
20
157
|
* Creates a wallet account on the Solana chain
|
|
@@ -423,12 +560,14 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
423
560
|
});
|
|
424
561
|
}
|
|
425
562
|
/**
|
|
426
|
-
*
|
|
563
|
+
* Builds and signs a Token-2022 confidential-transfer transaction.
|
|
427
564
|
*
|
|
428
565
|
* The enclave is offline, so missing account states and the latest
|
|
429
|
-
* blockhash are fetched from `rpcUrl`.
|
|
430
|
-
*
|
|
431
|
-
|
|
566
|
+
* blockhash are fetched from `rpcUrl`. The enclave builds one unsigned v1
|
|
567
|
+
* transaction bound by a `transactionsTag`; `signConfidentialTransactions`
|
|
568
|
+
* provisions one MPC room for the operation and the client share joins it.
|
|
569
|
+
* Pass `broadcast: true` to submit the signed transaction to the cluster.
|
|
570
|
+
*/ async signConfidentialTransfer({ walletId, operation, solanaAddress, mint, tokenAccount, destinationTokenAccount, amount, decimals, accountState, destinationAccountState, auditorElgamalPubkey, feePayer, derivationVersion, chainId = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', lamportsPerByte = '6960', recentBlockhash, lastValidBlockHeight, rpcUrl, broadcast = false, broadcastOptions, password, signedSessionId, mfaToken, elevatedAccessToken, traceContext }) {
|
|
432
571
|
const needsAccountState = operation === 'transfer' || operation === 'withdraw' || operation === 'applyPendingBalance';
|
|
433
572
|
const needsDestinationAccountState = operation === 'transfer';
|
|
434
573
|
const mustFetch = broadcast || needsAccountState && !accountState || needsDestinationAccountState && !destinationAccountState || !recentBlockhash || !lastValidBlockHeight;
|
|
@@ -447,7 +586,7 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
447
586
|
recentBlockhash,
|
|
448
587
|
lastValidBlockHeight
|
|
449
588
|
} : await this.confidentialBlockhash(rpcUrl);
|
|
450
|
-
const
|
|
589
|
+
const built = await this.apiClient.signConfidentialTransfer({
|
|
451
590
|
walletId,
|
|
452
591
|
request: {
|
|
453
592
|
accountState,
|
|
@@ -469,9 +608,86 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
469
608
|
},
|
|
470
609
|
traceContext
|
|
471
610
|
});
|
|
472
|
-
|
|
473
|
-
|
|
611
|
+
checkConfidentialTransactions({
|
|
612
|
+
serializedTransactions: built.serializedTransactions,
|
|
613
|
+
solanaAddress,
|
|
614
|
+
operation,
|
|
615
|
+
mint,
|
|
616
|
+
tokenAccount,
|
|
617
|
+
destinationTokenAccount,
|
|
618
|
+
amount,
|
|
619
|
+
decimals
|
|
620
|
+
});
|
|
621
|
+
const wireBytes = new Uint8Array(Buffer.from(built.serializedTransactions[0], 'base64'));
|
|
622
|
+
const signature = await this.queueSign(solanaAddress, async ()=>{
|
|
623
|
+
const { wallet, derivationPath, clientKeyShares } = await this.prepareWalletForSign({
|
|
624
|
+
accountAddress: solanaAddress,
|
|
625
|
+
password,
|
|
626
|
+
signedSessionId
|
|
627
|
+
});
|
|
628
|
+
const { roomIds } = await this.apiClient.signConfidentialTransactions({
|
|
629
|
+
walletId,
|
|
630
|
+
request: {
|
|
631
|
+
solanaAddress,
|
|
632
|
+
serializedTransactions: built.serializedTransactions,
|
|
633
|
+
transactionsTag: built.transactionsTag,
|
|
634
|
+
chainId
|
|
635
|
+
},
|
|
636
|
+
mfaToken,
|
|
637
|
+
elevatedAccessToken,
|
|
638
|
+
traceContext
|
|
639
|
+
});
|
|
640
|
+
if (roomIds.length !== 1) {
|
|
641
|
+
throw new Error('signConfidentialTransactions must return exactly one room');
|
|
642
|
+
}
|
|
643
|
+
// Join the one room redcoast provisioned over the relay (the enclave is already in);
|
|
644
|
+
// the check guarantees the wallet is the sole signer of the v1 message.
|
|
645
|
+
return await this.clientSign({
|
|
646
|
+
chainName: this.chainName,
|
|
647
|
+
message: confidentialSignedMessageBytes(wireBytes, 1),
|
|
648
|
+
roomId: roomIds[0],
|
|
649
|
+
keyShare: clientKeyShares[0],
|
|
650
|
+
derivationPath,
|
|
651
|
+
isFormatted: false,
|
|
652
|
+
dynamicRequestId: crypto.randomUUID(),
|
|
653
|
+
skipForwardMPC: true,
|
|
654
|
+
variant: wallet.variant,
|
|
655
|
+
traceContext
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
const signedTransactions = [
|
|
659
|
+
Buffer.from(injectConfidentialSignature(wireBytes, signature)).toString('base64')
|
|
660
|
+
];
|
|
661
|
+
const signatures = [
|
|
662
|
+
bs58.encode(signature)
|
|
663
|
+
];
|
|
664
|
+
const transactionIds = broadcast ? await this.broadcastConfidentialTransactions(rpcUrl, signedTransactions, broadcastOptions) : undefined;
|
|
665
|
+
return {
|
|
666
|
+
serializedTransactions: signedTransactions,
|
|
667
|
+
signatures,
|
|
474
668
|
transactionIds
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Returns the available and pending Token-2022 confidential balances for a
|
|
673
|
+
* token account. When `accountState` is omitted it is fetched from `rpcUrl`.
|
|
674
|
+
*/ async getConfidentialBalance({ walletId, solanaAddress, tokenAccount, mint, accountState, rpcUrl, derivationVersion, traceContext }) {
|
|
675
|
+
if (!accountState) {
|
|
676
|
+
if (!rpcUrl) {
|
|
677
|
+
throw new Error('getConfidentialBalance requires rpcUrl to fetch account state');
|
|
678
|
+
}
|
|
679
|
+
accountState = await this.svmAccountState(rpcUrl, tokenAccount);
|
|
680
|
+
}
|
|
681
|
+
return this.apiClient.getSvmConfidentialBalance({
|
|
682
|
+
walletId,
|
|
683
|
+
request: {
|
|
684
|
+
accountState,
|
|
685
|
+
derivationVersion,
|
|
686
|
+
mint,
|
|
687
|
+
solanaAddress,
|
|
688
|
+
tokenAccount
|
|
689
|
+
},
|
|
690
|
+
traceContext
|
|
475
691
|
});
|
|
476
692
|
}
|
|
477
693
|
async getSvmWallets() {
|
|
@@ -516,7 +732,8 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
516
732
|
const result = await this.svmRpcCall(rpcUrl, 'getAccountInfo', [
|
|
517
733
|
account,
|
|
518
734
|
{
|
|
519
|
-
encoding: 'base64'
|
|
735
|
+
encoding: 'base64',
|
|
736
|
+
commitment: 'confirmed'
|
|
520
737
|
}
|
|
521
738
|
]);
|
|
522
739
|
if (!(result == null ? void 0 : result.value)) {
|
|
@@ -545,7 +762,8 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
545
762
|
const transactionId = await this.svmRpcCall(rpcUrl, 'sendTransaction', [
|
|
546
763
|
serializedTransaction,
|
|
547
764
|
_extends({
|
|
548
|
-
encoding: 'base64'
|
|
765
|
+
encoding: 'base64',
|
|
766
|
+
preflightCommitment: 'confirmed'
|
|
549
767
|
}, broadcastOptions)
|
|
550
768
|
]);
|
|
551
769
|
// Confidential plans are order-dependent: confirm before submitting
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamicWalletClient, getMPCChainConfig, ERROR_KEYGEN_FAILED, ERROR_PASSWORD_MISMATCH, ERROR_MULTIPLE_WALLETS_PER_CHAIN, ERROR_CREATE_WALLET_ACCOUNT, ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_SIGN_MESSAGE, getEd25519PublicKeyFromRawScalar, ERROR_IMPORT_PRIVATE_KEY } from '@dynamic-labs-wallet/browser';
|
|
2
|
-
import {
|
|
2
|
+
import { SIGNATURE_LENGTH_IN_BYTES, VersionedTransaction, VersionedMessage, Keypair, PublicKey, SystemProgram, Message, MessageV0 } from '@solana/web3.js';
|
|
3
3
|
import bs58 from 'bs58';
|
|
4
4
|
|
|
5
5
|
function _extends() {
|
|
@@ -13,6 +13,143 @@ function _extends() {
|
|
|
13
13
|
return _extends.apply(this, arguments);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
const TOKEN_2022 = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
|
|
17
|
+
const ASSOCIATED_TOKEN = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
|
|
18
|
+
const SYSTEM = '11111111111111111111111111111111';
|
|
19
|
+
const ZK_ELGAMAL_PROOF = 'ZkE1Gama1Proof11111111111111111111111111111';
|
|
20
|
+
const COMPUTE_BUDGET = 'ComputeBudget111111111111111111111111111111';
|
|
21
|
+
const ALLOWED_PROGRAMS = new Set([
|
|
22
|
+
TOKEN_2022,
|
|
23
|
+
ASSOCIATED_TOKEN,
|
|
24
|
+
SYSTEM,
|
|
25
|
+
ZK_ELGAMAL_PROOF,
|
|
26
|
+
COMPUTE_BUDGET
|
|
27
|
+
]);
|
|
28
|
+
// Helper instructions the planner may emit alongside the confidential one.
|
|
29
|
+
const COMPUTE_SET_UNIT_LIMIT = 2;
|
|
30
|
+
const COMPUTE_SET_UNIT_PRICE = 3;
|
|
31
|
+
const ATA_CREATE = 0;
|
|
32
|
+
const ATA_CREATE_IDEMPOTENT = 1;
|
|
33
|
+
const SYSTEM_CREATE_ACCOUNT = 0;
|
|
34
|
+
const TOKEN_REALLOCATE = 29;
|
|
35
|
+
// Token-2022 ConfidentialTransferExtension (27) sub-instruction per operation.
|
|
36
|
+
const CONFIDENTIAL_EXTENSION = 27;
|
|
37
|
+
const SUB_INSTRUCTION = {
|
|
38
|
+
configureAccount: 2,
|
|
39
|
+
deposit: 5,
|
|
40
|
+
withdraw: 6,
|
|
41
|
+
transfer: 7,
|
|
42
|
+
applyPendingBalance: 8
|
|
43
|
+
};
|
|
44
|
+
const V1_PREFIX = 0x81;
|
|
45
|
+
const refuse = (reason)=>{
|
|
46
|
+
throw new Error(`Refusing to sign confidential transaction: ${reason}`);
|
|
47
|
+
};
|
|
48
|
+
/** Message bytes an MPC signer signs: a v1 wire is message || 64B signature slots. */ const confidentialSignedMessageBytes = (wire, numRequiredSignatures)=>wire.slice(0, wire.length - numRequiredSignatures * SIGNATURE_LENGTH_IN_BYTES);
|
|
49
|
+
/** Insert the wallet signature into the sole v1 signature slot (signer index 0). */ const injectConfidentialSignature = (wire, signature)=>Uint8Array.from([
|
|
50
|
+
...wire.slice(0, wire.length - SIGNATURE_LENGTH_IN_BYTES),
|
|
51
|
+
...signature
|
|
52
|
+
]);
|
|
53
|
+
const decodeV1Message = (encoded, solanaAddress)=>{
|
|
54
|
+
const wire = new Uint8Array(Buffer.from(encoded, 'base64'));
|
|
55
|
+
if (wire[0] !== V1_PREFIX) {
|
|
56
|
+
refuse('not a version 1 transaction');
|
|
57
|
+
}
|
|
58
|
+
let message;
|
|
59
|
+
try {
|
|
60
|
+
message = VersionedTransaction.deserialize(wire).message;
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return refuse('malformed transaction');
|
|
63
|
+
}
|
|
64
|
+
if (message.version !== 1) {
|
|
65
|
+
refuse('not a version 1 transaction');
|
|
66
|
+
}
|
|
67
|
+
if (message.header.numRequiredSignatures !== 1) {
|
|
68
|
+
refuse('unexpected extra signers');
|
|
69
|
+
}
|
|
70
|
+
const keys = message.staticAccountKeys.map((key)=>key.toBase58());
|
|
71
|
+
if (keys[0] !== solanaAddress) {
|
|
72
|
+
refuse('the wallet is not the fee payer');
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
message,
|
|
76
|
+
keys
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
const isAllowedHelperInstruction = (program, data)=>{
|
|
80
|
+
switch(program){
|
|
81
|
+
case COMPUTE_BUDGET:
|
|
82
|
+
return data[0] === COMPUTE_SET_UNIT_LIMIT || data[0] === COMPUTE_SET_UNIT_PRICE;
|
|
83
|
+
case ASSOCIATED_TOKEN:
|
|
84
|
+
return data.length === 0 || data[0] === ATA_CREATE || data[0] === ATA_CREATE_IDEMPOTENT;
|
|
85
|
+
case SYSTEM:
|
|
86
|
+
return data.length >= 4 && Buffer.from(data).readUInt32LE(0) === SYSTEM_CREATE_ACCOUNT;
|
|
87
|
+
case TOKEN_2022:
|
|
88
|
+
return data[0] === TOKEN_REALLOCATE;
|
|
89
|
+
default:
|
|
90
|
+
return program === ZK_ELGAMAL_PROOF;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const checkOperationInstruction = (data, accounts, params)=>{
|
|
94
|
+
const { operation, mint, tokenAccount, destinationTokenAccount, amount, decimals } = params;
|
|
95
|
+
if (data[1] !== SUB_INSTRUCTION[operation]) {
|
|
96
|
+
refuse(`confidential instruction ${data[1]} does not match ${operation}`);
|
|
97
|
+
}
|
|
98
|
+
if (accounts[0] !== tokenAccount) {
|
|
99
|
+
refuse('instruction targets an unexpected token account');
|
|
100
|
+
}
|
|
101
|
+
if (operation !== 'applyPendingBalance' && accounts[1] !== mint) {
|
|
102
|
+
refuse('instruction uses an unexpected mint');
|
|
103
|
+
}
|
|
104
|
+
if (operation === 'transfer' && (!destinationTokenAccount || accounts[2] !== destinationTokenAccount)) {
|
|
105
|
+
refuse('transfer destination does not match the request');
|
|
106
|
+
}
|
|
107
|
+
if (operation !== 'deposit' && operation !== 'withdraw') {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// Confidential amount layout: [27, sub, amount u64 LE, decimals u8, ...].
|
|
111
|
+
const bytes = Buffer.from(data);
|
|
112
|
+
if (amount === undefined || bytes.length < 11 || bytes.readBigUInt64LE(2).toString() !== amount) {
|
|
113
|
+
refuse(`${operation} amount does not match the request`);
|
|
114
|
+
}
|
|
115
|
+
if (decimals === undefined || bytes[10] !== decimals) {
|
|
116
|
+
refuse(`${operation} decimals do not match the request`);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Structural check on the enclave-built confidential transaction before the
|
|
121
|
+
* client share joins the MPC room: must be one v1 message, the wallet must be
|
|
122
|
+
* fee payer and only signer, only expected programs and instruction kinds may
|
|
123
|
+
* appear, and the confidential instruction must match the requested
|
|
124
|
+
* operation, mint, token accounts and amounts. The enclave's
|
|
125
|
+
* `transactionsTag` binds the build; this only guards against a bad build
|
|
126
|
+
* reaching the ceremony.
|
|
127
|
+
*/ const checkConfidentialTransactions = (params)=>{
|
|
128
|
+
if (params.serializedTransactions.length !== 1) {
|
|
129
|
+
refuse('expected exactly one version 1 transaction');
|
|
130
|
+
}
|
|
131
|
+
const { message, keys } = decodeV1Message(params.serializedTransactions[0], params.solanaAddress);
|
|
132
|
+
let sawOperation = false;
|
|
133
|
+
for (const ix of message.compiledInstructions){
|
|
134
|
+
const program = keys[ix.programIdIndex];
|
|
135
|
+
if (!program || !ALLOWED_PROGRAMS.has(program)) {
|
|
136
|
+
refuse(`unexpected program ${program}`);
|
|
137
|
+
}
|
|
138
|
+
if (program === TOKEN_2022 && ix.data[0] === CONFIDENTIAL_EXTENSION) {
|
|
139
|
+
if (sawOperation) {
|
|
140
|
+
refuse('more than one confidential instruction');
|
|
141
|
+
}
|
|
142
|
+
checkOperationInstruction(ix.data, ix.accountKeyIndexes.map((i)=>keys[i]), params);
|
|
143
|
+
sawOperation = true;
|
|
144
|
+
} else if (!isAllowedHelperInstruction(program, ix.data)) {
|
|
145
|
+
refuse(`unexpected instruction ${ix.data[0]} for program ${program}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!sawOperation) {
|
|
149
|
+
refuse(`no confidential instruction for ${params.operation}`);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
16
153
|
class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
17
154
|
/**
|
|
18
155
|
* Creates a wallet account on the Solana chain
|
|
@@ -421,12 +558,14 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
421
558
|
});
|
|
422
559
|
}
|
|
423
560
|
/**
|
|
424
|
-
*
|
|
561
|
+
* Builds and signs a Token-2022 confidential-transfer transaction.
|
|
425
562
|
*
|
|
426
563
|
* The enclave is offline, so missing account states and the latest
|
|
427
|
-
* blockhash are fetched from `rpcUrl`.
|
|
428
|
-
*
|
|
429
|
-
|
|
564
|
+
* blockhash are fetched from `rpcUrl`. The enclave builds one unsigned v1
|
|
565
|
+
* transaction bound by a `transactionsTag`; `signConfidentialTransactions`
|
|
566
|
+
* provisions one MPC room for the operation and the client share joins it.
|
|
567
|
+
* Pass `broadcast: true` to submit the signed transaction to the cluster.
|
|
568
|
+
*/ async signConfidentialTransfer({ walletId, operation, solanaAddress, mint, tokenAccount, destinationTokenAccount, amount, decimals, accountState, destinationAccountState, auditorElgamalPubkey, feePayer, derivationVersion, chainId = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', lamportsPerByte = '6960', recentBlockhash, lastValidBlockHeight, rpcUrl, broadcast = false, broadcastOptions, password, signedSessionId, mfaToken, elevatedAccessToken, traceContext }) {
|
|
430
569
|
const needsAccountState = operation === 'transfer' || operation === 'withdraw' || operation === 'applyPendingBalance';
|
|
431
570
|
const needsDestinationAccountState = operation === 'transfer';
|
|
432
571
|
const mustFetch = broadcast || needsAccountState && !accountState || needsDestinationAccountState && !destinationAccountState || !recentBlockhash || !lastValidBlockHeight;
|
|
@@ -445,7 +584,7 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
445
584
|
recentBlockhash,
|
|
446
585
|
lastValidBlockHeight
|
|
447
586
|
} : await this.confidentialBlockhash(rpcUrl);
|
|
448
|
-
const
|
|
587
|
+
const built = await this.apiClient.signConfidentialTransfer({
|
|
449
588
|
walletId,
|
|
450
589
|
request: {
|
|
451
590
|
accountState,
|
|
@@ -467,9 +606,86 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
467
606
|
},
|
|
468
607
|
traceContext
|
|
469
608
|
});
|
|
470
|
-
|
|
471
|
-
|
|
609
|
+
checkConfidentialTransactions({
|
|
610
|
+
serializedTransactions: built.serializedTransactions,
|
|
611
|
+
solanaAddress,
|
|
612
|
+
operation,
|
|
613
|
+
mint,
|
|
614
|
+
tokenAccount,
|
|
615
|
+
destinationTokenAccount,
|
|
616
|
+
amount,
|
|
617
|
+
decimals
|
|
618
|
+
});
|
|
619
|
+
const wireBytes = new Uint8Array(Buffer.from(built.serializedTransactions[0], 'base64'));
|
|
620
|
+
const signature = await this.queueSign(solanaAddress, async ()=>{
|
|
621
|
+
const { wallet, derivationPath, clientKeyShares } = await this.prepareWalletForSign({
|
|
622
|
+
accountAddress: solanaAddress,
|
|
623
|
+
password,
|
|
624
|
+
signedSessionId
|
|
625
|
+
});
|
|
626
|
+
const { roomIds } = await this.apiClient.signConfidentialTransactions({
|
|
627
|
+
walletId,
|
|
628
|
+
request: {
|
|
629
|
+
solanaAddress,
|
|
630
|
+
serializedTransactions: built.serializedTransactions,
|
|
631
|
+
transactionsTag: built.transactionsTag,
|
|
632
|
+
chainId
|
|
633
|
+
},
|
|
634
|
+
mfaToken,
|
|
635
|
+
elevatedAccessToken,
|
|
636
|
+
traceContext
|
|
637
|
+
});
|
|
638
|
+
if (roomIds.length !== 1) {
|
|
639
|
+
throw new Error('signConfidentialTransactions must return exactly one room');
|
|
640
|
+
}
|
|
641
|
+
// Join the one room redcoast provisioned over the relay (the enclave is already in);
|
|
642
|
+
// the check guarantees the wallet is the sole signer of the v1 message.
|
|
643
|
+
return await this.clientSign({
|
|
644
|
+
chainName: this.chainName,
|
|
645
|
+
message: confidentialSignedMessageBytes(wireBytes, 1),
|
|
646
|
+
roomId: roomIds[0],
|
|
647
|
+
keyShare: clientKeyShares[0],
|
|
648
|
+
derivationPath,
|
|
649
|
+
isFormatted: false,
|
|
650
|
+
dynamicRequestId: crypto.randomUUID(),
|
|
651
|
+
skipForwardMPC: true,
|
|
652
|
+
variant: wallet.variant,
|
|
653
|
+
traceContext
|
|
654
|
+
});
|
|
655
|
+
});
|
|
656
|
+
const signedTransactions = [
|
|
657
|
+
Buffer.from(injectConfidentialSignature(wireBytes, signature)).toString('base64')
|
|
658
|
+
];
|
|
659
|
+
const signatures = [
|
|
660
|
+
bs58.encode(signature)
|
|
661
|
+
];
|
|
662
|
+
const transactionIds = broadcast ? await this.broadcastConfidentialTransactions(rpcUrl, signedTransactions, broadcastOptions) : undefined;
|
|
663
|
+
return {
|
|
664
|
+
serializedTransactions: signedTransactions,
|
|
665
|
+
signatures,
|
|
472
666
|
transactionIds
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Returns the available and pending Token-2022 confidential balances for a
|
|
671
|
+
* token account. When `accountState` is omitted it is fetched from `rpcUrl`.
|
|
672
|
+
*/ async getConfidentialBalance({ walletId, solanaAddress, tokenAccount, mint, accountState, rpcUrl, derivationVersion, traceContext }) {
|
|
673
|
+
if (!accountState) {
|
|
674
|
+
if (!rpcUrl) {
|
|
675
|
+
throw new Error('getConfidentialBalance requires rpcUrl to fetch account state');
|
|
676
|
+
}
|
|
677
|
+
accountState = await this.svmAccountState(rpcUrl, tokenAccount);
|
|
678
|
+
}
|
|
679
|
+
return this.apiClient.getSvmConfidentialBalance({
|
|
680
|
+
walletId,
|
|
681
|
+
request: {
|
|
682
|
+
accountState,
|
|
683
|
+
derivationVersion,
|
|
684
|
+
mint,
|
|
685
|
+
solanaAddress,
|
|
686
|
+
tokenAccount
|
|
687
|
+
},
|
|
688
|
+
traceContext
|
|
473
689
|
});
|
|
474
690
|
}
|
|
475
691
|
async getSvmWallets() {
|
|
@@ -514,7 +730,8 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
514
730
|
const result = await this.svmRpcCall(rpcUrl, 'getAccountInfo', [
|
|
515
731
|
account,
|
|
516
732
|
{
|
|
517
|
-
encoding: 'base64'
|
|
733
|
+
encoding: 'base64',
|
|
734
|
+
commitment: 'confirmed'
|
|
518
735
|
}
|
|
519
736
|
]);
|
|
520
737
|
if (!(result == null ? void 0 : result.value)) {
|
|
@@ -543,7 +760,8 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
543
760
|
const transactionId = await this.svmRpcCall(rpcUrl, 'sendTransaction', [
|
|
544
761
|
serializedTransaction,
|
|
545
762
|
_extends({
|
|
546
|
-
encoding: 'base64'
|
|
763
|
+
encoding: 'base64',
|
|
764
|
+
preflightCommitment: 'confirmed'
|
|
547
765
|
}, broadcastOptions)
|
|
548
766
|
]);
|
|
549
767
|
// Confidential plans are order-dependent: confirm before submitting
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/svm",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.64",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@dynamic-labs-wallet/browser": "1.1.
|
|
8
|
-
"@dynamic-labs-wallet/core": "1.1.
|
|
9
|
-
"@solana/web3.js": "
|
|
7
|
+
"@dynamic-labs-wallet/browser": "1.1.64",
|
|
8
|
+
"@dynamic-labs-wallet/core": "1.1.64",
|
|
9
|
+
"@solana/web3.js": "1.99.0",
|
|
10
10
|
"bs58": "^6.0.0",
|
|
11
11
|
"@dynamic-labs/sdk-api-core": "0.144.0"
|
|
12
12
|
},
|
package/src/svm/client.d.ts
CHANGED
|
@@ -161,13 +161,15 @@ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
161
161
|
traceContext?: TraceContext;
|
|
162
162
|
}): Promise<import("@dynamic-labs-wallet/browser").CreateConfidentialSeedResponse>;
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
164
|
+
* Builds and signs a Token-2022 confidential-transfer transaction.
|
|
165
165
|
*
|
|
166
166
|
* The enclave is offline, so missing account states and the latest
|
|
167
|
-
* blockhash are fetched from `rpcUrl`.
|
|
168
|
-
*
|
|
167
|
+
* blockhash are fetched from `rpcUrl`. The enclave builds one unsigned v1
|
|
168
|
+
* transaction bound by a `transactionsTag`; `signConfidentialTransactions`
|
|
169
|
+
* provisions one MPC room for the operation and the client share joins it.
|
|
170
|
+
* Pass `broadcast: true` to submit the signed transaction to the cluster.
|
|
169
171
|
*/
|
|
170
|
-
signConfidentialTransfer({ walletId, operation, solanaAddress, mint, tokenAccount, destinationTokenAccount, amount, decimals, accountState, destinationAccountState, auditorElgamalPubkey, feePayer, derivationVersion, chainId, lamportsPerByte, recentBlockhash, lastValidBlockHeight, rpcUrl, broadcast, broadcastOptions, traceContext, }: {
|
|
172
|
+
signConfidentialTransfer({ walletId, operation, solanaAddress, mint, tokenAccount, destinationTokenAccount, amount, decimals, accountState, destinationAccountState, auditorElgamalPubkey, feePayer, derivationVersion, chainId, lamportsPerByte, recentBlockhash, lastValidBlockHeight, rpcUrl, broadcast, broadcastOptions, password, signedSessionId, mfaToken, elevatedAccessToken, traceContext, }: {
|
|
171
173
|
walletId: string;
|
|
172
174
|
operation: ConfidentialTransferOperation;
|
|
173
175
|
solanaAddress: string;
|
|
@@ -193,12 +195,31 @@ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
193
195
|
skipPreflight?: boolean;
|
|
194
196
|
preflightCommitment?: string;
|
|
195
197
|
};
|
|
198
|
+
password?: string;
|
|
199
|
+
signedSessionId: string;
|
|
200
|
+
mfaToken?: string;
|
|
201
|
+
elevatedAccessToken?: string;
|
|
196
202
|
traceContext?: TraceContext;
|
|
197
203
|
}): Promise<{
|
|
198
|
-
transactionIds: string[] | undefined;
|
|
199
204
|
serializedTransactions: string[];
|
|
200
205
|
signatures: string[];
|
|
206
|
+
transactionIds: string[] | undefined;
|
|
201
207
|
}>;
|
|
208
|
+
/**
|
|
209
|
+
* Returns the available and pending Token-2022 confidential balances for a
|
|
210
|
+
* token account. When `accountState` is omitted it is fetched from `rpcUrl`.
|
|
211
|
+
*/
|
|
212
|
+
getConfidentialBalance({ walletId, solanaAddress, tokenAccount, mint, accountState, rpcUrl, derivationVersion, traceContext, }: {
|
|
213
|
+
walletId: string;
|
|
214
|
+
solanaAddress: string;
|
|
215
|
+
tokenAccount: string;
|
|
216
|
+
mint: string;
|
|
217
|
+
/** Fetched from `rpcUrl` when omitted. */
|
|
218
|
+
accountState?: ConfidentialAccountState;
|
|
219
|
+
rpcUrl?: string;
|
|
220
|
+
derivationVersion?: number;
|
|
221
|
+
traceContext?: TraceContext;
|
|
222
|
+
}): Promise<import("@dynamic-labs-wallet/browser").SvmConfidentialBalanceResponse>;
|
|
202
223
|
getSvmWallets(): Promise<any>;
|
|
203
224
|
}
|
|
204
225
|
//# sourceMappingURL=client.d.ts.map
|
package/src/svm/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/svm/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAUnB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,8BAA8B,EAEnC,KAAK,cAAc,EAEnB,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,EACnC,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/svm/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAUnB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,8BAA8B,EAEnC,KAAK,cAAc,EAEnB,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,EACnC,MAAM,8BAA8B,CAAC;AAuBtC,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CAAC,SAAS,SAAS;IAC3B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAEjC;;;;;OAKG;IACG,mBAAmB,CAAC,EACxB,wBAAwB,EACxB,QAAoB,EACpB,eAAe,EACf,YAAY,EACZ,iBAAiB,GAClB,EAAE;QACD,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,eAAe,EA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AiB,EACjB,YAAY,GACb,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,0CAA0C;QAC1C,YAAY,CAAC,EAAE,wBAAwB,CAAC;QACxC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,YAAY,CAAC,EAAE,YAAY,CAAC;KAC7B;IAcK,aAAa;CAKpB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ConfidentialTransferOperation } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
/** Message bytes an MPC signer signs: a v1 wire is message || 64B signature slots. */
|
|
3
|
+
export declare const confidentialSignedMessageBytes: (wire: Uint8Array, numRequiredSignatures: number) => Uint8Array;
|
|
4
|
+
/** Insert the wallet signature into the sole v1 signature slot (signer index 0). */
|
|
5
|
+
export declare const injectConfidentialSignature: (wire: Uint8Array, signature: Uint8Array) => Uint8Array;
|
|
6
|
+
type ConfidentialCheckParams = {
|
|
7
|
+
serializedTransactions: string[];
|
|
8
|
+
solanaAddress: string;
|
|
9
|
+
operation: ConfidentialTransferOperation;
|
|
10
|
+
mint: string;
|
|
11
|
+
tokenAccount: string;
|
|
12
|
+
destinationTokenAccount?: string;
|
|
13
|
+
amount?: string;
|
|
14
|
+
decimals?: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Structural check on the enclave-built confidential transaction before the
|
|
18
|
+
* client share joins the MPC room: must be one v1 message, the wallet must be
|
|
19
|
+
* fee payer and only signer, only expected programs and instruction kinds may
|
|
20
|
+
* appear, and the confidential instruction must match the requested
|
|
21
|
+
* operation, mint, token accounts and amounts. The enclave's
|
|
22
|
+
* `transactionsTag` binds the build; this only guards against a bad build
|
|
23
|
+
* reaching the ceremony.
|
|
24
|
+
*/
|
|
25
|
+
export declare const checkConfidentialTransactions: (params: ConfidentialCheckParams) => void;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=confidentialCheck.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confidentialCheck.d.ts","sourceRoot":"","sources":["../../src/svm/confidentialCheck.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAiClF,sFAAsF;AACtF,eAAO,MAAM,8BAA8B,SAAU,UAAU,yBAAyB,MAAM,KAAG,UACjB,CAAC;AAEjF,oFAAoF;AACpF,eAAO,MAAM,2BAA2B,SAAU,UAAU,aAAa,UAAU,KAAG,UACM,CAAC;AAE7F,KAAK,uBAAuB,GAAG;IAC7B,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,6BAA6B,CAAC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAoEF;;;;;;;;GAQG;AACH,eAAO,MAAM,6BAA6B,WAAY,uBAAuB,KAAG,IA4B/E,CAAC"}
|