@solana/compat 2.0.0-experimental.fcff844 → 2.0.0-experimental.fd64233
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 +1 -1
- package/dist/index.browser.cjs +2 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +2 -0
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +2 -0
- package/dist/index.node.js.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/transaction.d.ts.map +1 -1
- package/package.json +12 -11
- package/dist/index.development.js +0 -435
- package/dist/index.development.js.map +0 -1
- package/dist/index.production.min.js +0 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/transaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/transaction.ts"],"names":[],"mappings":"AAMA,OAAO,EAGH,KAAK,wBAAwB,EAE7B,KAAK,iCAAiC,EACtC,KAAK,wBAAwB,EAM7B,KAAK,WAAW,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAKR,oBAAoB,EACvB,MAAM,iBAAiB,CAAC;AAkEzB,wBAAgB,qCAAqC,CACjD,WAAW,EAAE,oBAAoB,EACjC,oBAAoB,CAAC,EAAE,MAAM,GAC9B,WAAW,GAAG,wBAAwB,GAAG,iCAAiC,CAqC5E;AAED,wBAAgB,wCAAwC,CACpD,WAAW,EAAE,oBAAoB,GAClC,WAAW,GAAG,wBAAwB,GAAG,wBAAwB,CAwDnE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/compat",
|
|
3
|
-
"version": "2.0.0-experimental.
|
|
3
|
+
"version": "2.0.0-experimental.fd64233",
|
|
4
4
|
"description": "Helpers for converting from legacy web3js classes",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -49,16 +49,16 @@
|
|
|
49
49
|
"node": ">=17.4"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@solana/functional": "2.0.0-experimental.
|
|
53
|
-
"@solana/
|
|
54
|
-
"@solana/
|
|
55
|
-
"@solana/
|
|
52
|
+
"@solana/functional": "2.0.0-experimental.fd64233",
|
|
53
|
+
"@solana/instructions": "2.0.0-experimental.fd64233",
|
|
54
|
+
"@solana/transactions": "2.0.0-experimental.fd64233",
|
|
55
|
+
"@solana/keys": "2.0.0-experimental.fd64233"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@solana/eslint-config-solana": "^1.0.2",
|
|
59
59
|
"@swc/jest": "^0.2.29",
|
|
60
|
-
"@types/jest": "^29.5.
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
60
|
+
"@types/jest": "^29.5.11",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
62
62
|
"@typescript-eslint/parser": "^6.3.0",
|
|
63
63
|
"agadoo": "^3.0.0",
|
|
64
64
|
"eslint": "^8.45.0",
|
|
@@ -72,9 +72,10 @@
|
|
|
72
72
|
"tsup": "^8.0.1",
|
|
73
73
|
"typescript": "^5.2.2",
|
|
74
74
|
"version-from-git": "^1.1.1",
|
|
75
|
-
"@solana/addresses": "2.0.0-experimental.
|
|
76
|
-
"@solana/keys": "2.0.0-experimental.
|
|
75
|
+
"@solana/addresses": "2.0.0-experimental.fd64233",
|
|
76
|
+
"@solana/keys": "2.0.0-experimental.fd64233",
|
|
77
77
|
"@solana/web3.js": "0.0.0-development",
|
|
78
|
+
"@solana/rpc-types": "2.0.0-experimental.fd64233",
|
|
78
79
|
"build-scripts": "0.0.0",
|
|
79
80
|
"test-config": "0.0.0",
|
|
80
81
|
"tsconfig": "0.0.0"
|
|
@@ -88,8 +89,8 @@
|
|
|
88
89
|
]
|
|
89
90
|
},
|
|
90
91
|
"scripts": {
|
|
91
|
-
"compile:js": "tsup --config build-scripts/tsup.config.
|
|
92
|
-
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
92
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
|
|
93
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/build-scripts/add-js-extension-to-types.mjs",
|
|
93
94
|
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
94
95
|
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
|
|
95
96
|
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
|
|
@@ -1,435 +0,0 @@
|
|
|
1
|
-
this.globalThis = this.globalThis || {};
|
|
2
|
-
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
// src/address.ts
|
|
6
|
-
function fromLegacyPublicKey(publicKey) {
|
|
7
|
-
return publicKey.toBase58();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// ../codecs-core/dist/index.browser.js
|
|
11
|
-
function getEncodedSize(value, encoder) {
|
|
12
|
-
return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
|
|
13
|
-
}
|
|
14
|
-
function createEncoder(encoder) {
|
|
15
|
-
return Object.freeze({
|
|
16
|
-
...encoder,
|
|
17
|
-
encode: (value) => {
|
|
18
|
-
const bytes = new Uint8Array(getEncodedSize(value, encoder));
|
|
19
|
-
encoder.write(value, bytes, 0);
|
|
20
|
-
return bytes;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// ../codecs-strings/dist/index.browser.js
|
|
26
|
-
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
27
|
-
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
28
|
-
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
var getBaseXEncoder = (alphabet4) => {
|
|
32
|
-
return createEncoder({
|
|
33
|
-
getSizeFromValue: (value) => {
|
|
34
|
-
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
|
|
35
|
-
if (tailChars === "")
|
|
36
|
-
return value.length;
|
|
37
|
-
const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
|
|
38
|
-
return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
|
|
39
|
-
},
|
|
40
|
-
write(value, bytes, offset) {
|
|
41
|
-
assertValidBaseString(alphabet4, value);
|
|
42
|
-
if (value === "")
|
|
43
|
-
return offset;
|
|
44
|
-
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
|
|
45
|
-
if (tailChars === "") {
|
|
46
|
-
bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
|
|
47
|
-
return offset + leadingZeroes.length;
|
|
48
|
-
}
|
|
49
|
-
let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
|
|
50
|
-
const tailBytes = [];
|
|
51
|
-
while (base10Number > 0n) {
|
|
52
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
53
|
-
base10Number /= 256n;
|
|
54
|
-
}
|
|
55
|
-
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
|
|
56
|
-
bytes.set(bytesToAdd, offset);
|
|
57
|
-
return offset + bytesToAdd.length;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
function partitionLeadingZeroes(value, zeroCharacter) {
|
|
62
|
-
const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
|
|
63
|
-
return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
|
|
64
|
-
}
|
|
65
|
-
function getBigIntFromBaseX(value, alphabet4) {
|
|
66
|
-
const base = BigInt(alphabet4.length);
|
|
67
|
-
return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
|
|
68
|
-
}
|
|
69
|
-
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
70
|
-
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
71
|
-
|
|
72
|
-
// ../keys/dist/index.browser.js
|
|
73
|
-
function addPkcs8Header(bytes) {
|
|
74
|
-
return new Uint8Array([
|
|
75
|
-
/**
|
|
76
|
-
* PKCS#8 header
|
|
77
|
-
*/
|
|
78
|
-
48,
|
|
79
|
-
// ASN.1 sequence tag
|
|
80
|
-
46,
|
|
81
|
-
// Length of sequence (46 more bytes)
|
|
82
|
-
2,
|
|
83
|
-
// ASN.1 integer tag
|
|
84
|
-
1,
|
|
85
|
-
// Length of integer
|
|
86
|
-
0,
|
|
87
|
-
// Version number
|
|
88
|
-
48,
|
|
89
|
-
// ASN.1 sequence tag
|
|
90
|
-
5,
|
|
91
|
-
// Length of sequence
|
|
92
|
-
6,
|
|
93
|
-
// ASN.1 object identifier tag
|
|
94
|
-
3,
|
|
95
|
-
// Length of object identifier
|
|
96
|
-
// Edwards curve algorithms identifier https://oid-rep.orange-labs.fr/get/1.3.101.112
|
|
97
|
-
43,
|
|
98
|
-
// iso(1) / identified-organization(3) (The first node is multiplied by the decimal 40 and the result is added to the value of the second node)
|
|
99
|
-
101,
|
|
100
|
-
// thawte(101)
|
|
101
|
-
// Ed25519 identifier
|
|
102
|
-
112,
|
|
103
|
-
// id-Ed25519(112)
|
|
104
|
-
/**
|
|
105
|
-
* Private key payload
|
|
106
|
-
*/
|
|
107
|
-
4,
|
|
108
|
-
// ASN.1 octet string tag
|
|
109
|
-
34,
|
|
110
|
-
// String length (34 more bytes)
|
|
111
|
-
// Private key bytes as octet string
|
|
112
|
-
4,
|
|
113
|
-
// ASN.1 octet string tag
|
|
114
|
-
32,
|
|
115
|
-
// String length (32 bytes)
|
|
116
|
-
...bytes
|
|
117
|
-
]);
|
|
118
|
-
}
|
|
119
|
-
async function createPrivateKeyFromBytes(bytes, extractable) {
|
|
120
|
-
if (bytes.byteLength !== 32) {
|
|
121
|
-
throw new Error("Private key bytes must be of length 32");
|
|
122
|
-
}
|
|
123
|
-
const privateKeyBytesPkcs8 = addPkcs8Header(bytes);
|
|
124
|
-
return await crypto.subtle.importKey("pkcs8", privateKeyBytesPkcs8, "Ed25519", extractable != null ? extractable : false, ["sign"]);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// src/keypair.ts
|
|
128
|
-
async function fromLegacyKeypair(keypair, extractable) {
|
|
129
|
-
const [publicKey, privateKey] = await Promise.all([
|
|
130
|
-
crypto.subtle.importKey("raw", keypair.publicKey.toBytes(), "Ed25519", true, ["verify"]),
|
|
131
|
-
createPrivateKeyFromBytes(keypair.secretKey.slice(0, 32), extractable)
|
|
132
|
-
]);
|
|
133
|
-
return {
|
|
134
|
-
privateKey,
|
|
135
|
-
publicKey
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// ../addresses/dist/index.browser.js
|
|
140
|
-
var memoizedBase58Encoder;
|
|
141
|
-
function getMemoizedBase58Encoder() {
|
|
142
|
-
if (!memoizedBase58Encoder)
|
|
143
|
-
memoizedBase58Encoder = getBase58Encoder();
|
|
144
|
-
return memoizedBase58Encoder;
|
|
145
|
-
}
|
|
146
|
-
function assertIsAddress(putativeAddress) {
|
|
147
|
-
try {
|
|
148
|
-
if (
|
|
149
|
-
// Lowest address (32 bytes of zeroes)
|
|
150
|
-
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
151
|
-
putativeAddress.length > 44
|
|
152
|
-
) {
|
|
153
|
-
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
154
|
-
}
|
|
155
|
-
const base58Encoder = getMemoizedBase58Encoder();
|
|
156
|
-
const bytes = base58Encoder.encode(putativeAddress);
|
|
157
|
-
const numBytes = bytes.byteLength;
|
|
158
|
-
if (numBytes !== 32) {
|
|
159
|
-
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
160
|
-
}
|
|
161
|
-
} catch (e2) {
|
|
162
|
-
throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
|
|
163
|
-
cause: e2
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// ../functional/dist/index.browser.js
|
|
169
|
-
function pipe(init, ...fns) {
|
|
170
|
-
return fns.reduce((acc, fn) => fn(acc), init);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// ../instructions/dist/index.browser.js
|
|
174
|
-
var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
|
|
175
|
-
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
176
|
-
3] = "WRITABLE_SIGNER";
|
|
177
|
-
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
178
|
-
2] = "READONLY_SIGNER";
|
|
179
|
-
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
180
|
-
1] = "WRITABLE";
|
|
181
|
-
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
182
|
-
0] = "READONLY";
|
|
183
|
-
return AccountRole22;
|
|
184
|
-
})(AccountRole || {});
|
|
185
|
-
|
|
186
|
-
// ../transactions/dist/index.browser.js
|
|
187
|
-
function getUnsignedTransaction(transaction) {
|
|
188
|
-
if ("signatures" in transaction) {
|
|
189
|
-
const {
|
|
190
|
-
signatures: _,
|
|
191
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
192
|
-
...unsignedTransaction
|
|
193
|
-
} = transaction;
|
|
194
|
-
return unsignedTransaction;
|
|
195
|
-
} else {
|
|
196
|
-
return transaction;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
200
|
-
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
201
|
-
return transaction;
|
|
202
|
-
}
|
|
203
|
-
const out = {
|
|
204
|
-
...getUnsignedTransaction(transaction),
|
|
205
|
-
lifetimeConstraint: blockhashLifetimeConstraint
|
|
206
|
-
};
|
|
207
|
-
Object.freeze(out);
|
|
208
|
-
return out;
|
|
209
|
-
}
|
|
210
|
-
function createTransaction({
|
|
211
|
-
version
|
|
212
|
-
}) {
|
|
213
|
-
const out = {
|
|
214
|
-
instructions: [],
|
|
215
|
-
version
|
|
216
|
-
};
|
|
217
|
-
Object.freeze(out);
|
|
218
|
-
return out;
|
|
219
|
-
}
|
|
220
|
-
var AccountRole2 = /* @__PURE__ */ ((AccountRole22) => {
|
|
221
|
-
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
222
|
-
3] = "WRITABLE_SIGNER";
|
|
223
|
-
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
224
|
-
2] = "READONLY_SIGNER";
|
|
225
|
-
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
226
|
-
1] = "WRITABLE";
|
|
227
|
-
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
228
|
-
0] = "READONLY";
|
|
229
|
-
return AccountRole22;
|
|
230
|
-
})(AccountRole2 || {});
|
|
231
|
-
function isSignerRole(role) {
|
|
232
|
-
return role >= 2;
|
|
233
|
-
}
|
|
234
|
-
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
235
|
-
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
236
|
-
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
237
|
-
return {
|
|
238
|
-
accounts: [
|
|
239
|
-
{ address: nonceAccountAddress, role: AccountRole2.WRITABLE },
|
|
240
|
-
{
|
|
241
|
-
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
242
|
-
role: AccountRole2.READONLY
|
|
243
|
-
},
|
|
244
|
-
{ address: nonceAuthorityAddress, role: AccountRole2.READONLY_SIGNER }
|
|
245
|
-
],
|
|
246
|
-
data: new Uint8Array([4, 0, 0, 0]),
|
|
247
|
-
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function isAdvanceNonceAccountInstruction(instruction) {
|
|
251
|
-
var _a;
|
|
252
|
-
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
253
|
-
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
254
|
-
((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
|
|
255
|
-
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole2.WRITABLE && // Second account is recent blockhashes sysvar
|
|
256
|
-
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole2.READONLY && // Third account is nonce authority account
|
|
257
|
-
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
258
|
-
}
|
|
259
|
-
function isAdvanceNonceAccountInstructionData(data) {
|
|
260
|
-
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
261
|
-
}
|
|
262
|
-
function isDurableNonceTransaction(transaction) {
|
|
263
|
-
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
264
|
-
}
|
|
265
|
-
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
266
|
-
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
267
|
-
}
|
|
268
|
-
function setTransactionLifetimeUsingDurableNonce({
|
|
269
|
-
nonce,
|
|
270
|
-
nonceAccountAddress,
|
|
271
|
-
nonceAuthorityAddress
|
|
272
|
-
}, transaction) {
|
|
273
|
-
let newInstructions;
|
|
274
|
-
const firstInstruction = transaction.instructions[0];
|
|
275
|
-
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
276
|
-
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
277
|
-
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
278
|
-
return transaction;
|
|
279
|
-
} else {
|
|
280
|
-
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
281
|
-
}
|
|
282
|
-
} else {
|
|
283
|
-
newInstructions = [
|
|
284
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
285
|
-
...transaction.instructions.slice(1)
|
|
286
|
-
];
|
|
287
|
-
}
|
|
288
|
-
} else {
|
|
289
|
-
newInstructions = [
|
|
290
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
291
|
-
...transaction.instructions
|
|
292
|
-
];
|
|
293
|
-
}
|
|
294
|
-
const out = {
|
|
295
|
-
...getUnsignedTransaction(transaction),
|
|
296
|
-
instructions: newInstructions,
|
|
297
|
-
lifetimeConstraint: {
|
|
298
|
-
nonce
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
Object.freeze(out);
|
|
302
|
-
return out;
|
|
303
|
-
}
|
|
304
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
305
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
306
|
-
return transaction;
|
|
307
|
-
}
|
|
308
|
-
const out = {
|
|
309
|
-
...getUnsignedTransaction(transaction),
|
|
310
|
-
feePayer
|
|
311
|
-
};
|
|
312
|
-
Object.freeze(out);
|
|
313
|
-
return out;
|
|
314
|
-
}
|
|
315
|
-
function appendTransactionInstruction(instruction, transaction) {
|
|
316
|
-
const out = {
|
|
317
|
-
...getUnsignedTransaction(transaction),
|
|
318
|
-
instructions: [...transaction.instructions, instruction]
|
|
319
|
-
};
|
|
320
|
-
Object.freeze(out);
|
|
321
|
-
return out;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// src/transaction.ts
|
|
325
|
-
function convertAccount(message, accountKeys, accountIndex) {
|
|
326
|
-
const accountPublicKey = accountKeys.get(accountIndex);
|
|
327
|
-
if (!accountPublicKey) {
|
|
328
|
-
throw new Error(`Could not find account address at index ${accountIndex}`);
|
|
329
|
-
}
|
|
330
|
-
const isSigner = message.isAccountSigner(accountIndex);
|
|
331
|
-
const isWritable = message.isAccountWritable(accountIndex);
|
|
332
|
-
const role = isSigner ? isWritable ? AccountRole.WRITABLE_SIGNER : AccountRole.READONLY_SIGNER : isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;
|
|
333
|
-
return {
|
|
334
|
-
address: accountPublicKey.toBase58(),
|
|
335
|
-
role
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
function convertInstruction(message, accountKeys, instruction) {
|
|
339
|
-
const programAddressPublicKey = accountKeys.get(instruction.programIdIndex);
|
|
340
|
-
if (!programAddressPublicKey) {
|
|
341
|
-
throw new Error(`Could not find program address at index ${instruction.programIdIndex}`);
|
|
342
|
-
}
|
|
343
|
-
const accounts = instruction.accountKeyIndexes.map(
|
|
344
|
-
(accountIndex) => convertAccount(message, accountKeys, accountIndex)
|
|
345
|
-
);
|
|
346
|
-
return {
|
|
347
|
-
programAddress: programAddressPublicKey.toBase58(),
|
|
348
|
-
...accounts.length ? { accounts } : {},
|
|
349
|
-
...instruction.data.length ? { data: instruction.data } : {}
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
function convertSignatures(transaction, staticAccountKeys) {
|
|
353
|
-
return transaction.signatures.reduce((acc, sig, index) => {
|
|
354
|
-
const allZeros = sig.every((byte) => byte === 0);
|
|
355
|
-
if (allZeros)
|
|
356
|
-
return acc;
|
|
357
|
-
const address = staticAccountKeys[index].toBase58();
|
|
358
|
-
return { ...acc, [address]: sig };
|
|
359
|
-
}, {});
|
|
360
|
-
}
|
|
361
|
-
function fromVersionedTransactionWithBlockhash(transaction, lastValidBlockHeight) {
|
|
362
|
-
if (transaction.message.addressTableLookups.length > 0) {
|
|
363
|
-
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
364
|
-
}
|
|
365
|
-
const accountKeys = transaction.message.getAccountKeys();
|
|
366
|
-
const feePayer = accountKeys.staticAccountKeys[0];
|
|
367
|
-
if (!feePayer)
|
|
368
|
-
throw new Error("No fee payer set in VersionedTransaction");
|
|
369
|
-
const blockhashLifetime = {
|
|
370
|
-
blockhash: transaction.message.recentBlockhash,
|
|
371
|
-
lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
|
|
372
|
-
// U64 MAX
|
|
373
|
-
};
|
|
374
|
-
const instructions = transaction.message.compiledInstructions.map(
|
|
375
|
-
(instruction) => convertInstruction(transaction.message, accountKeys, instruction)
|
|
376
|
-
);
|
|
377
|
-
const signatures = convertSignatures(transaction, accountKeys.staticAccountKeys);
|
|
378
|
-
return pipe(
|
|
379
|
-
createTransaction({ version: transaction.version }),
|
|
380
|
-
(tx) => setTransactionFeePayer(feePayer.toBase58(), tx),
|
|
381
|
-
(tx) => setTransactionLifetimeUsingBlockhash(blockhashLifetime, tx),
|
|
382
|
-
(tx) => instructions.reduce((acc, instruction) => {
|
|
383
|
-
return appendTransactionInstruction(instruction, acc);
|
|
384
|
-
}, tx),
|
|
385
|
-
(tx) => transaction.signatures.length ? { ...tx, signatures } : tx
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
function fromVersionedTransactionWithDurableNonce(transaction) {
|
|
389
|
-
if (transaction.message.addressTableLookups.length > 0) {
|
|
390
|
-
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
391
|
-
}
|
|
392
|
-
const accountKeys = transaction.message.getAccountKeys();
|
|
393
|
-
const feePayer = accountKeys.staticAccountKeys[0];
|
|
394
|
-
if (!feePayer)
|
|
395
|
-
throw new Error("No fee payer set in VersionedTransaction");
|
|
396
|
-
const instructions = transaction.message.compiledInstructions.map(
|
|
397
|
-
(instruction) => convertInstruction(transaction.message, accountKeys, instruction)
|
|
398
|
-
);
|
|
399
|
-
if (instructions.length === 0) {
|
|
400
|
-
throw new Error("transaction with no instructions cannot be durable nonce transaction");
|
|
401
|
-
}
|
|
402
|
-
if (!isAdvanceNonceAccountInstruction(instructions[0])) {
|
|
403
|
-
throw new Error("transaction first instruction is not advance nonce account instruction");
|
|
404
|
-
}
|
|
405
|
-
const nonceAccountAddress = instructions[0].accounts[0].address;
|
|
406
|
-
assertIsAddress(nonceAccountAddress);
|
|
407
|
-
const nonceAuthorityAddress = instructions[0].accounts[2].address;
|
|
408
|
-
assertIsAddress(nonceAuthorityAddress);
|
|
409
|
-
const durableNonceLifetime = {
|
|
410
|
-
nonce: transaction.message.recentBlockhash,
|
|
411
|
-
nonceAccountAddress,
|
|
412
|
-
nonceAuthorityAddress
|
|
413
|
-
};
|
|
414
|
-
const signatures = convertSignatures(transaction, accountKeys.staticAccountKeys);
|
|
415
|
-
return pipe(
|
|
416
|
-
createTransaction({ version: transaction.version }),
|
|
417
|
-
(tx) => setTransactionFeePayer(feePayer.toBase58(), tx),
|
|
418
|
-
(tx) => setTransactionLifetimeUsingDurableNonce(durableNonceLifetime, tx),
|
|
419
|
-
(tx) => instructions.slice(1).reduce((acc, instruction) => {
|
|
420
|
-
return appendTransactionInstruction(instruction, acc);
|
|
421
|
-
}, tx),
|
|
422
|
-
(tx) => transaction.signatures.length ? { ...tx, signatures } : tx
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
exports.fromLegacyKeypair = fromLegacyKeypair;
|
|
427
|
-
exports.fromLegacyPublicKey = fromLegacyPublicKey;
|
|
428
|
-
exports.fromVersionedTransactionWithBlockhash = fromVersionedTransactionWithBlockhash;
|
|
429
|
-
exports.fromVersionedTransactionWithDurableNonce = fromVersionedTransactionWithDurableNonce;
|
|
430
|
-
|
|
431
|
-
return exports;
|
|
432
|
-
|
|
433
|
-
})({});
|
|
434
|
-
//# sourceMappingURL=out.js.map
|
|
435
|
-
//# sourceMappingURL=index.development.js.map
|