@solana/transactions 2.0.0-experimental.6910664 → 2.0.0-experimental.699bde0
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 -43
- package/dist/index.browser.cjs +24 -66
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +26 -64
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +477 -549
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +26 -64
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +26 -66
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +24 -64
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +18 -20
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/compilable-transaction.d.ts +7 -0
- package/dist/types/compile-address-table-lookups.d.ts +2 -2
- package/dist/types/compile-static-accounts.d.ts +2 -2
- package/dist/types/compile-transaction.d.ts +5 -6
- package/dist/types/decompile-transaction.d.ts +2 -4
- package/dist/types/durable-nonce.d.ts +3 -3
- package/dist/types/fee-payer.d.ts +4 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/types/message.d.ts +1 -5
- package/dist/types/serializers/transaction.d.ts +1 -3
- package/dist/types/signatures.d.ts +8 -13
- package/dist/types/types.d.ts +6 -13
- package/package.json +13 -14
- package/dist/types/accounts.d.ts.map +0 -1
- package/dist/types/blockhash.d.ts.map +0 -1
- package/dist/types/compile-address-table-lookups.d.ts.map +0 -1
- package/dist/types/compile-header.d.ts.map +0 -1
- package/dist/types/compile-instructions.d.ts.map +0 -1
- package/dist/types/compile-lifetime-token.d.ts.map +0 -1
- package/dist/types/compile-static-accounts.d.ts.map +0 -1
- package/dist/types/compile-transaction.d.ts.map +0 -1
- package/dist/types/create-transaction.d.ts.map +0 -1
- package/dist/types/decompile-transaction.d.ts.map +0 -1
- package/dist/types/durable-nonce.d.ts.map +0 -1
- package/dist/types/fee-payer.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/instructions.d.ts.map +0 -1
- package/dist/types/message.d.ts.map +0 -1
- package/dist/types/serializers/address-table-lookup.d.ts.map +0 -1
- package/dist/types/serializers/header.d.ts.map +0 -1
- package/dist/types/serializers/index.d.ts.map +0 -1
- package/dist/types/serializers/instruction.d.ts.map +0 -1
- package/dist/types/serializers/message.d.ts.map +0 -1
- package/dist/types/serializers/transaction-version.d.ts.map +0 -1
- package/dist/types/serializers/transaction.d.ts.map +0 -1
- package/dist/types/signatures.d.ts.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/unsigned-transaction.d.ts.map +0 -1
- package/dist/types/wire-transaction.d.ts.map +0 -1
package/dist/index.native.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getBase58Encoder, getBase58Decoder, getBase64Decoder, getStringEncoder, getStringDecoder } from '@solana/codecs-strings';
|
|
2
2
|
import { mapEncoder, mapDecoder, combineCodec } from '@solana/codecs-core';
|
|
3
3
|
import { getStructEncoder, getArrayEncoder, getBytesEncoder, getStructDecoder, getArrayDecoder, getBytesDecoder } from '@solana/codecs-data-structures';
|
|
4
4
|
import { getShortU16Encoder, getShortU16Decoder, getU8Encoder, getU8Decoder } from '@solana/codecs-numbers';
|
|
5
5
|
import { getAddressFromPublicKey, getAddressComparator, assertIsAddress, getAddressEncoder, getAddressDecoder } from '@solana/addresses';
|
|
6
6
|
import { pipe } from '@solana/functional';
|
|
7
|
-
import { getStringEncoder, getBase58Encoder, getStringDecoder, getBase58Decoder } from '@solana/codecs-strings';
|
|
8
7
|
import { signBytes } from '@solana/keys';
|
|
9
8
|
|
|
10
9
|
// ../build-scripts/env-shim.ts
|
|
@@ -25,7 +24,10 @@ function getUnsignedTransaction(transaction) {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
// src/blockhash.ts
|
|
27
|
+
var base58Encoder;
|
|
28
28
|
function assertIsBlockhash(putativeBlockhash) {
|
|
29
|
+
if (!base58Encoder)
|
|
30
|
+
base58Encoder = getBase58Encoder();
|
|
29
31
|
try {
|
|
30
32
|
if (
|
|
31
33
|
// Lowest value (32 bytes of zeroes)
|
|
@@ -34,7 +36,7 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
34
36
|
) {
|
|
35
37
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
36
38
|
}
|
|
37
|
-
const bytes =
|
|
39
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
38
40
|
const numBytes = bytes.byteLength;
|
|
39
41
|
if (numBytes !== 32) {
|
|
40
42
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
@@ -250,7 +252,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
250
252
|
const shouldReplaceEntry = (
|
|
251
253
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
252
254
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
253
|
-
(addressComparator
|
|
255
|
+
(addressComparator ||= getAddressComparator())(
|
|
254
256
|
accountMeta.lookupTableAddress,
|
|
255
257
|
entry.lookupTableAddress
|
|
256
258
|
) < 0
|
|
@@ -356,7 +358,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
356
358
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
357
359
|
return leftIsWritable ? -1 : 1;
|
|
358
360
|
}
|
|
359
|
-
addressComparator
|
|
361
|
+
addressComparator ||= getAddressComparator();
|
|
360
362
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
361
363
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
362
364
|
} else {
|
|
@@ -369,16 +371,15 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
369
371
|
return orderedAccounts;
|
|
370
372
|
}
|
|
371
373
|
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
372
|
-
var _a;
|
|
373
374
|
const index = {};
|
|
374
375
|
for (const account of orderedAccounts) {
|
|
375
376
|
if (!("lookupTableAddress" in account)) {
|
|
376
377
|
continue;
|
|
377
378
|
}
|
|
378
|
-
const entry = index[
|
|
379
|
+
const entry = index[account.lookupTableAddress] ||= {
|
|
379
380
|
readableIndices: [],
|
|
380
381
|
writableIndices: []
|
|
381
|
-
}
|
|
382
|
+
};
|
|
382
383
|
if (account.role === AccountRole.WRITABLE) {
|
|
383
384
|
entry.writableIndices.push(account.addressIndex);
|
|
384
385
|
} else {
|
|
@@ -979,65 +980,26 @@ function getTransactionDecoder(lastValidBlockHeight) {
|
|
|
979
980
|
function getTransactionCodec(lastValidBlockHeight) {
|
|
980
981
|
return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
981
982
|
}
|
|
982
|
-
|
|
983
|
-
try {
|
|
984
|
-
if (
|
|
985
|
-
// Lowest value (64 bytes of zeroes)
|
|
986
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
987
|
-
putativeTransactionSignature.length > 88
|
|
988
|
-
) {
|
|
989
|
-
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
990
|
-
}
|
|
991
|
-
const bytes = base58.serialize(putativeTransactionSignature);
|
|
992
|
-
const numBytes = bytes.byteLength;
|
|
993
|
-
if (numBytes !== 64) {
|
|
994
|
-
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
995
|
-
}
|
|
996
|
-
} catch (e) {
|
|
997
|
-
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
998
|
-
cause: e
|
|
999
|
-
});
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
function isTransactionSignature(putativeTransactionSignature) {
|
|
1003
|
-
if (
|
|
1004
|
-
// Lowest value (64 bytes of zeroes)
|
|
1005
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1006
|
-
putativeTransactionSignature.length > 88
|
|
1007
|
-
) {
|
|
1008
|
-
return false;
|
|
1009
|
-
}
|
|
1010
|
-
const bytes = base58.serialize(putativeTransactionSignature);
|
|
1011
|
-
const numBytes = bytes.byteLength;
|
|
1012
|
-
if (numBytes !== 64) {
|
|
1013
|
-
return false;
|
|
1014
|
-
}
|
|
1015
|
-
return true;
|
|
1016
|
-
}
|
|
1017
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
1018
|
-
const wireMessageBytes = getCompiledMessageEncoder().encode(message);
|
|
1019
|
-
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
1020
|
-
return signature;
|
|
1021
|
-
}
|
|
983
|
+
var base58Decoder;
|
|
1022
984
|
function getSignatureFromTransaction(transaction) {
|
|
985
|
+
if (!base58Decoder)
|
|
986
|
+
base58Decoder = getBase58Decoder();
|
|
1023
987
|
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
1024
988
|
if (!signatureBytes) {
|
|
1025
989
|
throw new Error(
|
|
1026
990
|
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1027
991
|
);
|
|
1028
992
|
}
|
|
1029
|
-
const
|
|
1030
|
-
return
|
|
993
|
+
const transactionSignature = base58Decoder.decode(signatureBytes)[0];
|
|
994
|
+
return transactionSignature;
|
|
1031
995
|
}
|
|
1032
|
-
async function
|
|
996
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
1033
997
|
const compiledMessage = compileMessage(transaction);
|
|
1034
998
|
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
999
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
1035
1000
|
const publicKeySignaturePairs = await Promise.all(
|
|
1036
1001
|
keyPairs.map(
|
|
1037
|
-
(keyPair) => Promise.all([
|
|
1038
|
-
getAddressFromPublicKey(keyPair.publicKey),
|
|
1039
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
1040
|
-
])
|
|
1002
|
+
(keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
|
|
1041
1003
|
)
|
|
1042
1004
|
);
|
|
1043
1005
|
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
@@ -1050,9 +1012,11 @@ async function signTransaction(keyPairs, transaction) {
|
|
|
1050
1012
|
Object.freeze(out);
|
|
1051
1013
|
return out;
|
|
1052
1014
|
}
|
|
1053
|
-
function
|
|
1054
|
-
|
|
1055
|
-
|
|
1015
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1016
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
1017
|
+
assertTransactionIsFullySigned(out);
|
|
1018
|
+
Object.freeze(out);
|
|
1019
|
+
return out;
|
|
1056
1020
|
}
|
|
1057
1021
|
function assertTransactionIsFullySigned(transaction) {
|
|
1058
1022
|
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
|
|
@@ -1063,13 +1027,11 @@ function assertTransactionIsFullySigned(transaction) {
|
|
|
1063
1027
|
}
|
|
1064
1028
|
});
|
|
1065
1029
|
}
|
|
1066
|
-
|
|
1067
|
-
// src/wire-transaction.ts
|
|
1068
1030
|
function getBase64EncodedWireTransaction(transaction) {
|
|
1069
1031
|
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1070
|
-
|
|
1071
|
-
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1072
|
-
}
|
|
1032
|
+
return getBase64Decoder().decode(wireTransactionBytes)[0];
|
|
1073
1033
|
}
|
|
1074
1034
|
|
|
1075
|
-
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction,
|
|
1035
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertTransactionIsFullySigned, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionCodec, getTransactionDecoder, getTransactionEncoder, isAdvanceNonceAccountInstruction, partiallySignTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };
|
|
1036
|
+
//# sourceMappingURL=out.js.map
|
|
1037
|
+
//# sourceMappingURL=index.native.js.map
|