@solana/transactions 2.0.0-experimental.f07dced → 2.0.0-experimental.f27be12
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.browser.cjs +229 -113
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +223 -115
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +282 -163
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +225 -115
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +229 -113
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +223 -115
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +16 -8
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts +6 -1
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts +1 -1
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
- package/dist/types/compile-header.d.ts.map +1 -0
- package/dist/types/compile-instructions.d.ts +1 -1
- package/dist/types/compile-instructions.d.ts.map +1 -0
- package/dist/types/compile-lifetime-token.d.ts.map +1 -0
- package/dist/types/compile-static-accounts.d.ts +1 -1
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts.map +1 -0
- package/dist/types/create-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +20 -7
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts +3 -2
- package/dist/types/fee-payer.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instructions.d.ts.map +1 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
- package/dist/types/serializers/header.d.ts.map +1 -0
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts.map +1 -0
- package/dist/types/serializers/message.d.ts.map +1 -0
- package/dist/types/serializers/transaction-version.d.ts.map +1 -0
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/serializers/unimplemented.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +13 -6
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/unsigned-transaction.d.ts +4 -0
- package/dist/types/unsigned-transaction.d.ts.map +1 -0
- package/dist/types/wire-transaction.d.ts +1 -1
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +18 -18
package/dist/index.browser.js
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { base58, struct, array, bytes, shortU16, mapSerializer, string, u8 } from '@metaplex-foundation/umi-serializers';
|
|
2
|
-
import {
|
|
2
|
+
import { getAddressFromPublicKey, getAddressComparator, getAddressCodec } from '@solana/addresses';
|
|
3
|
+
import { signBytes } from '@solana/keys';
|
|
3
4
|
|
|
4
5
|
// ../build-scripts/env-shim.ts
|
|
5
6
|
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
|
|
7
|
+
|
|
8
|
+
// src/unsigned-transaction.ts
|
|
9
|
+
function getUnsignedTransaction(transaction) {
|
|
10
|
+
if ("signatures" in transaction) {
|
|
11
|
+
const {
|
|
12
|
+
signatures: _,
|
|
13
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
14
|
+
...unsignedTransaction
|
|
15
|
+
} = transaction;
|
|
16
|
+
return unsignedTransaction;
|
|
17
|
+
} else {
|
|
18
|
+
return transaction;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/blockhash.ts
|
|
6
23
|
function assertIsBlockhash(putativeBlockhash) {
|
|
7
24
|
try {
|
|
8
25
|
if (
|
|
@@ -23,6 +40,17 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
23
40
|
});
|
|
24
41
|
}
|
|
25
42
|
}
|
|
43
|
+
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
44
|
+
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
45
|
+
return transaction;
|
|
46
|
+
}
|
|
47
|
+
const out = {
|
|
48
|
+
...getUnsignedTransaction(transaction),
|
|
49
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
50
|
+
};
|
|
51
|
+
Object.freeze(out);
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
26
54
|
|
|
27
55
|
// src/create-transaction.ts
|
|
28
56
|
function createTransaction({
|
|
@@ -36,66 +64,6 @@ function createTransaction({
|
|
|
36
64
|
return out;
|
|
37
65
|
}
|
|
38
66
|
|
|
39
|
-
// src/fee-payer.ts
|
|
40
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
41
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
42
|
-
return transaction;
|
|
43
|
-
}
|
|
44
|
-
let out;
|
|
45
|
-
if ("signatures" in transaction) {
|
|
46
|
-
const {
|
|
47
|
-
signatures: _,
|
|
48
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
49
|
-
...unsignedTransaction
|
|
50
|
-
} = transaction;
|
|
51
|
-
out = {
|
|
52
|
-
...unsignedTransaction,
|
|
53
|
-
feePayer
|
|
54
|
-
};
|
|
55
|
-
} else {
|
|
56
|
-
out = {
|
|
57
|
-
...transaction,
|
|
58
|
-
feePayer
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
Object.freeze(out);
|
|
62
|
-
return out;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/instructions.ts
|
|
66
|
-
function replaceInstructions(transaction, nextInstructions) {
|
|
67
|
-
let out;
|
|
68
|
-
if ("signatures" in transaction) {
|
|
69
|
-
const {
|
|
70
|
-
signatures: _,
|
|
71
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
72
|
-
...unsignedTransaction
|
|
73
|
-
} = transaction;
|
|
74
|
-
out = {
|
|
75
|
-
...unsignedTransaction,
|
|
76
|
-
instructions: nextInstructions
|
|
77
|
-
};
|
|
78
|
-
} else {
|
|
79
|
-
out = {
|
|
80
|
-
...transaction,
|
|
81
|
-
instructions: nextInstructions
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return out;
|
|
85
|
-
}
|
|
86
|
-
function appendTransactionInstruction(instruction, transaction) {
|
|
87
|
-
const nextInstructions = [...transaction.instructions, instruction];
|
|
88
|
-
const out = replaceInstructions(transaction, nextInstructions);
|
|
89
|
-
Object.freeze(out);
|
|
90
|
-
return out;
|
|
91
|
-
}
|
|
92
|
-
function prependTransactionInstruction(instruction, transaction) {
|
|
93
|
-
const nextInstructions = [instruction, ...transaction.instructions];
|
|
94
|
-
const out = replaceInstructions(transaction, nextInstructions);
|
|
95
|
-
Object.freeze(out);
|
|
96
|
-
return out;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
67
|
// ../instructions/dist/index.browser.js
|
|
100
68
|
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
101
69
|
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
@@ -118,6 +86,96 @@ function isWritableRole(role) {
|
|
|
118
86
|
function mergeRoles(roleA, roleB) {
|
|
119
87
|
return roleA | roleB;
|
|
120
88
|
}
|
|
89
|
+
|
|
90
|
+
// src/durable-nonce.ts
|
|
91
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
92
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
93
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
94
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
95
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
99
|
+
return {
|
|
100
|
+
accounts: [
|
|
101
|
+
{ address: nonceAccountAddress, role: AccountRole.WRITABLE },
|
|
102
|
+
{
|
|
103
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
104
|
+
role: AccountRole.READONLY
|
|
105
|
+
},
|
|
106
|
+
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
|
|
107
|
+
],
|
|
108
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
109
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
113
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
114
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
115
|
+
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
116
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
117
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
118
|
+
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
|
|
119
|
+
}
|
|
120
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
121
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
122
|
+
}
|
|
123
|
+
function isDurableNonceTransaction(transaction) {
|
|
124
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
125
|
+
}
|
|
126
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
127
|
+
nonce,
|
|
128
|
+
nonceAccountAddress,
|
|
129
|
+
nonceAuthorityAddress
|
|
130
|
+
}, transaction) {
|
|
131
|
+
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
|
|
132
|
+
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
|
|
133
|
+
return transaction;
|
|
134
|
+
}
|
|
135
|
+
const out = {
|
|
136
|
+
...getUnsignedTransaction(transaction),
|
|
137
|
+
instructions: [
|
|
138
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
139
|
+
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
140
|
+
],
|
|
141
|
+
lifetimeConstraint: {
|
|
142
|
+
nonce
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
Object.freeze(out);
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/fee-payer.ts
|
|
150
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
151
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
152
|
+
return transaction;
|
|
153
|
+
}
|
|
154
|
+
const out = {
|
|
155
|
+
...getUnsignedTransaction(transaction),
|
|
156
|
+
feePayer
|
|
157
|
+
};
|
|
158
|
+
Object.freeze(out);
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/instructions.ts
|
|
163
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
164
|
+
const out = {
|
|
165
|
+
...getUnsignedTransaction(transaction),
|
|
166
|
+
instructions: [...transaction.instructions, instruction]
|
|
167
|
+
};
|
|
168
|
+
Object.freeze(out);
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
172
|
+
const out = {
|
|
173
|
+
...getUnsignedTransaction(transaction),
|
|
174
|
+
instructions: [instruction, ...transaction.instructions]
|
|
175
|
+
};
|
|
176
|
+
Object.freeze(out);
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
121
179
|
function upsert(addressMap, address, update) {
|
|
122
180
|
addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
|
|
123
181
|
}
|
|
@@ -170,7 +228,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
170
228
|
const shouldReplaceEntry = (
|
|
171
229
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
172
230
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
173
|
-
(addressComparator || (addressComparator =
|
|
231
|
+
(addressComparator || (addressComparator = getAddressComparator()))(
|
|
174
232
|
accountMeta.lookupTableAddress,
|
|
175
233
|
entry.lookupTableAddress
|
|
176
234
|
) < 0
|
|
@@ -276,7 +334,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
276
334
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
277
335
|
return leftIsWritable ? -1 : 1;
|
|
278
336
|
}
|
|
279
|
-
addressComparator || (addressComparator =
|
|
337
|
+
addressComparator || (addressComparator = getAddressComparator());
|
|
280
338
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
281
339
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
282
340
|
} else {
|
|
@@ -305,7 +363,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
305
363
|
entry.readableIndices.push(account.addressIndex);
|
|
306
364
|
}
|
|
307
365
|
}
|
|
308
|
-
return Object.keys(index).sort(
|
|
366
|
+
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
|
|
309
367
|
lookupTableAddress,
|
|
310
368
|
...index[lookupTableAddress]
|
|
311
369
|
}));
|
|
@@ -384,12 +442,30 @@ function compileMessage(transaction) {
|
|
|
384
442
|
version: transaction.version
|
|
385
443
|
};
|
|
386
444
|
}
|
|
445
|
+
|
|
446
|
+
// src/compile-transaction.ts
|
|
447
|
+
function getCompiledTransaction(transaction) {
|
|
448
|
+
const compiledMessage = compileMessage(transaction);
|
|
449
|
+
let signatures;
|
|
450
|
+
if ("signatures" in transaction) {
|
|
451
|
+
signatures = [];
|
|
452
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
453
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
454
|
+
}
|
|
455
|
+
} else {
|
|
456
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
457
|
+
}
|
|
458
|
+
return {
|
|
459
|
+
compiledMessage,
|
|
460
|
+
signatures
|
|
461
|
+
};
|
|
462
|
+
}
|
|
387
463
|
function getAddressTableLookupCodec() {
|
|
388
464
|
return struct(
|
|
389
465
|
[
|
|
390
466
|
[
|
|
391
467
|
"lookupTableAddress",
|
|
392
|
-
|
|
468
|
+
getAddressCodec(
|
|
393
469
|
__DEV__ ? {
|
|
394
470
|
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
395
471
|
} : void 0
|
|
@@ -464,7 +540,7 @@ function getInstructionCodec() {
|
|
|
464
540
|
)
|
|
465
541
|
],
|
|
466
542
|
[
|
|
467
|
-
"
|
|
543
|
+
"accountIndices",
|
|
468
544
|
array(
|
|
469
545
|
u8({
|
|
470
546
|
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
@@ -484,23 +560,23 @@ function getInstructionCodec() {
|
|
|
484
560
|
]
|
|
485
561
|
]),
|
|
486
562
|
(value) => {
|
|
487
|
-
if (value.
|
|
563
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
488
564
|
return value;
|
|
489
565
|
}
|
|
490
566
|
return {
|
|
491
567
|
...value,
|
|
492
|
-
|
|
568
|
+
accountIndices: value.accountIndices ?? [],
|
|
493
569
|
data: value.data ?? new Uint8Array(0)
|
|
494
570
|
};
|
|
495
571
|
},
|
|
496
572
|
(value) => {
|
|
497
|
-
if (value.
|
|
573
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
498
574
|
return value;
|
|
499
575
|
}
|
|
500
|
-
const {
|
|
576
|
+
const { accountIndices, data, ...rest } = value;
|
|
501
577
|
return {
|
|
502
578
|
...rest,
|
|
503
|
-
...
|
|
579
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
504
580
|
...data.byteLength ? { data } : null
|
|
505
581
|
};
|
|
506
582
|
}
|
|
@@ -586,7 +662,7 @@ function getPreludeStructSerializerTuple() {
|
|
|
586
662
|
["header", getMessageHeaderCodec()],
|
|
587
663
|
[
|
|
588
664
|
"staticAccounts",
|
|
589
|
-
array(
|
|
665
|
+
array(getAddressCodec(), {
|
|
590
666
|
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
|
|
591
667
|
size: shortU16()
|
|
592
668
|
})
|
|
@@ -622,48 +698,6 @@ function getCompiledMessageEncoder() {
|
|
|
622
698
|
};
|
|
623
699
|
}
|
|
624
700
|
|
|
625
|
-
// src/signatures.ts
|
|
626
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
627
|
-
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
628
|
-
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
629
|
-
return signature;
|
|
630
|
-
}
|
|
631
|
-
async function signTransaction(keyPair, transaction) {
|
|
632
|
-
const compiledMessage = compileMessage(transaction);
|
|
633
|
-
const [signerPublicKey, signature] = await Promise.all([
|
|
634
|
-
getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
|
|
635
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
636
|
-
]);
|
|
637
|
-
const nextSignatures = {
|
|
638
|
-
..."signatures" in transaction ? transaction.signatures : null,
|
|
639
|
-
...{ [signerPublicKey]: signature }
|
|
640
|
-
};
|
|
641
|
-
const out = {
|
|
642
|
-
...transaction,
|
|
643
|
-
signatures: nextSignatures
|
|
644
|
-
};
|
|
645
|
-
Object.freeze(out);
|
|
646
|
-
return out;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
// src/compile-transaction.ts
|
|
650
|
-
function getCompiledTransaction(transaction) {
|
|
651
|
-
const compiledMessage = compileMessage(transaction);
|
|
652
|
-
let signatures;
|
|
653
|
-
if ("signatures" in transaction) {
|
|
654
|
-
signatures = [];
|
|
655
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
656
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
657
|
-
}
|
|
658
|
-
} else {
|
|
659
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
660
|
-
}
|
|
661
|
-
return {
|
|
662
|
-
compiledMessage,
|
|
663
|
-
signatures
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
|
|
667
701
|
// src/serializers/transaction.ts
|
|
668
702
|
var BASE_CONFIG3 = {
|
|
669
703
|
description: __DEV__ ? "The wire format of a Solana transaction" : "",
|
|
@@ -690,6 +724,80 @@ function getTransactionEncoder() {
|
|
|
690
724
|
serialize: serialize3
|
|
691
725
|
};
|
|
692
726
|
}
|
|
727
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
728
|
+
try {
|
|
729
|
+
if (
|
|
730
|
+
// Lowest value (64 bytes of zeroes)
|
|
731
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
732
|
+
putativeTransactionSignature.length > 88
|
|
733
|
+
) {
|
|
734
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
735
|
+
}
|
|
736
|
+
const bytes3 = base58.serialize(putativeTransactionSignature);
|
|
737
|
+
const numBytes = bytes3.byteLength;
|
|
738
|
+
if (numBytes !== 64) {
|
|
739
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
740
|
+
}
|
|
741
|
+
} catch (e) {
|
|
742
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
743
|
+
cause: e
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
748
|
+
if (
|
|
749
|
+
// Lowest value (64 bytes of zeroes)
|
|
750
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
751
|
+
putativeTransactionSignature.length > 88
|
|
752
|
+
) {
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
const bytes3 = base58.serialize(putativeTransactionSignature);
|
|
756
|
+
const numBytes = bytes3.byteLength;
|
|
757
|
+
if (numBytes !== 64) {
|
|
758
|
+
return false;
|
|
759
|
+
}
|
|
760
|
+
return true;
|
|
761
|
+
}
|
|
762
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
763
|
+
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
764
|
+
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
765
|
+
return signature;
|
|
766
|
+
}
|
|
767
|
+
function getSignatureFromTransaction(transaction) {
|
|
768
|
+
const signature = transaction.signatures[transaction.feePayer];
|
|
769
|
+
if (!signature) {
|
|
770
|
+
throw new Error(
|
|
771
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
return signature;
|
|
775
|
+
}
|
|
776
|
+
async function signTransaction(keyPairs, transaction) {
|
|
777
|
+
const compiledMessage = compileMessage(transaction);
|
|
778
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
779
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
780
|
+
keyPairs.map(
|
|
781
|
+
(keyPair) => Promise.all([
|
|
782
|
+
getAddressFromPublicKey(keyPair.publicKey),
|
|
783
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
784
|
+
])
|
|
785
|
+
)
|
|
786
|
+
);
|
|
787
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
788
|
+
nextSignatures[signerPublicKey] = signature;
|
|
789
|
+
}
|
|
790
|
+
const out = {
|
|
791
|
+
...transaction,
|
|
792
|
+
signatures: nextSignatures
|
|
793
|
+
};
|
|
794
|
+
Object.freeze(out);
|
|
795
|
+
return out;
|
|
796
|
+
}
|
|
797
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
798
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
799
|
+
return putativeTransactionSignature;
|
|
800
|
+
}
|
|
693
801
|
|
|
694
802
|
// src/wire-transaction.ts
|
|
695
803
|
function getBase64EncodedWireTransaction(transaction) {
|
|
@@ -699,6 +807,6 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
699
807
|
}
|
|
700
808
|
}
|
|
701
809
|
|
|
702
|
-
export { appendTransactionInstruction, assertIsBlockhash, createTransaction, getBase64EncodedWireTransaction, prependTransactionInstruction, setTransactionFeePayer, signTransaction };
|
|
810
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
|
|
703
811
|
//# sourceMappingURL=out.js.map
|
|
704
812
|
//# sourceMappingURL=index.browser.js.map
|