@solana/transactions 2.0.0-experimental.7000add → 2.0.0-experimental.70ec746
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/LICENSE +1 -1
- package/dist/index.browser.cjs +297 -185
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +292 -188
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +958 -239
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +292 -188
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +295 -187
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +292 -188
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +17 -11
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/blockhash.d.ts +1 -1
- package/dist/types/compile-address-table-lookups.d.ts +1 -1
- package/dist/types/compile-instructions.d.ts +1 -1
- package/dist/types/compile-static-accounts.d.ts +1 -1
- package/dist/types/durable-nonce.d.ts +6 -4
- package/dist/types/fee-payer.d.ts +3 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts +5 -3
- package/dist/types/serializers/header.d.ts +4 -2
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/serializers/instruction.d.ts +4 -2
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/dist/types/signatures.d.ts +12 -3
- package/dist/types/types.d.ts +7 -0
- package/dist/types/wire-transaction.d.ts +1 -1
- package/package.json +21 -18
- 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/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/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/serializers/unimplemented.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/LICENSE
CHANGED
package/dist/index.browser.cjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
4
|
+
var addresses = require('@solana/addresses');
|
|
5
|
+
var codecsCore = require('@solana/codecs-core');
|
|
6
|
+
var codecsDataStructures = require('@solana/codecs-data-structures');
|
|
7
|
+
var codecsNumbers = require('@solana/codecs-numbers');
|
|
4
8
|
var keys = require('@solana/keys');
|
|
5
9
|
|
|
6
10
|
// ../build-scripts/env-shim.ts
|
|
@@ -30,8 +34,8 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
30
34
|
) {
|
|
31
35
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
32
36
|
}
|
|
33
|
-
const
|
|
34
|
-
const numBytes =
|
|
37
|
+
const bytes2 = umiSerializers.base58.serialize(putativeBlockhash);
|
|
38
|
+
const numBytes = bytes2.byteLength;
|
|
35
39
|
if (numBytes !== 32) {
|
|
36
40
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
37
41
|
}
|
|
@@ -229,7 +233,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
229
233
|
const shouldReplaceEntry = (
|
|
230
234
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
231
235
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
232
|
-
(addressComparator || (addressComparator =
|
|
236
|
+
(addressComparator || (addressComparator = addresses.getAddressComparator()))(
|
|
233
237
|
accountMeta.lookupTableAddress,
|
|
234
238
|
entry.lookupTableAddress
|
|
235
239
|
) < 0
|
|
@@ -335,7 +339,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
335
339
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
336
340
|
return leftIsWritable ? -1 : 1;
|
|
337
341
|
}
|
|
338
|
-
addressComparator || (addressComparator =
|
|
342
|
+
addressComparator || (addressComparator = addresses.getAddressComparator());
|
|
339
343
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
340
344
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
341
345
|
} else {
|
|
@@ -364,7 +368,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
364
368
|
entry.readableIndices.push(account.addressIndex);
|
|
365
369
|
}
|
|
366
370
|
}
|
|
367
|
-
return Object.keys(index).sort(
|
|
371
|
+
return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
|
|
368
372
|
lookupTableAddress,
|
|
369
373
|
...index[lookupTableAddress]
|
|
370
374
|
}));
|
|
@@ -443,151 +447,188 @@ function compileMessage(transaction) {
|
|
|
443
447
|
version: transaction.version
|
|
444
448
|
};
|
|
445
449
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
450
|
+
|
|
451
|
+
// src/compile-transaction.ts
|
|
452
|
+
function getCompiledTransaction(transaction) {
|
|
453
|
+
const compiledMessage = compileMessage(transaction);
|
|
454
|
+
let signatures;
|
|
455
|
+
if ("signatures" in transaction) {
|
|
456
|
+
signatures = [];
|
|
457
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
458
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
461
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
462
|
+
}
|
|
463
|
+
return {
|
|
464
|
+
compiledMessage,
|
|
465
|
+
signatures
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
469
|
+
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
470
|
+
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
471
|
+
var addressTableLookupDescription = __DEV__ ? "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" : "addressTableLookup";
|
|
472
|
+
var memoizedAddressTableLookupEncoder;
|
|
473
|
+
function getAddressTableLookupEncoder() {
|
|
474
|
+
if (!memoizedAddressTableLookupEncoder) {
|
|
475
|
+
memoizedAddressTableLookupEncoder = codecsDataStructures.getStructEncoder(
|
|
449
476
|
[
|
|
450
|
-
"lookupTableAddress",
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
477
|
+
["lookupTableAddress", addresses.getAddressEncoder({ description: lookupTableAddressDescription })],
|
|
478
|
+
[
|
|
479
|
+
"writableIndices",
|
|
480
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
|
|
481
|
+
description: writableIndicesDescription,
|
|
482
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
483
|
+
})
|
|
484
|
+
],
|
|
485
|
+
[
|
|
486
|
+
"readableIndices",
|
|
487
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
|
|
488
|
+
description: readableIndicesDescription,
|
|
489
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
490
|
+
})
|
|
491
|
+
]
|
|
456
492
|
],
|
|
493
|
+
{ description: addressTableLookupDescription }
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
return memoizedAddressTableLookupEncoder;
|
|
497
|
+
}
|
|
498
|
+
var memoizedAddressTableLookupDecoder;
|
|
499
|
+
function getAddressTableLookupDecoder() {
|
|
500
|
+
if (!memoizedAddressTableLookupDecoder) {
|
|
501
|
+
memoizedAddressTableLookupDecoder = codecsDataStructures.getStructDecoder(
|
|
457
502
|
[
|
|
458
|
-
"
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
503
|
+
["lookupTableAddress", addresses.getAddressDecoder({ description: lookupTableAddressDescription })],
|
|
504
|
+
[
|
|
505
|
+
"writableIndices",
|
|
506
|
+
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
|
|
507
|
+
description: writableIndicesDescription,
|
|
508
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
509
|
+
})
|
|
510
|
+
],
|
|
511
|
+
[
|
|
512
|
+
"readableIndices",
|
|
513
|
+
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
|
|
514
|
+
description: readableIndicesDescription,
|
|
515
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
516
|
+
})
|
|
517
|
+
]
|
|
465
518
|
],
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
519
|
+
{ description: addressTableLookupDescription }
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
return memoizedAddressTableLookupDecoder;
|
|
523
|
+
}
|
|
524
|
+
function getAddressTableLookupCodec() {
|
|
525
|
+
return codecsCore.combineCodec(getAddressTableLookupEncoder(), getAddressTableLookupDecoder());
|
|
526
|
+
}
|
|
527
|
+
var memoizedU8Codec;
|
|
528
|
+
function getMemoizedU8Codec() {
|
|
529
|
+
if (!memoizedU8Codec)
|
|
530
|
+
memoizedU8Codec = codecsNumbers.getU8Codec();
|
|
531
|
+
return memoizedU8Codec;
|
|
532
|
+
}
|
|
533
|
+
function getMemoizedU8CodecDescription(description) {
|
|
534
|
+
const codec = getMemoizedU8Codec();
|
|
535
|
+
return {
|
|
536
|
+
...codec,
|
|
537
|
+
description: description ?? codec.description
|
|
538
|
+
};
|
|
480
539
|
}
|
|
540
|
+
var numSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" : void 0;
|
|
541
|
+
var numReadonlySignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" : void 0;
|
|
542
|
+
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
543
|
+
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
481
544
|
function getMessageHeaderCodec() {
|
|
482
|
-
return
|
|
545
|
+
return codecsDataStructures.getStructCodec(
|
|
483
546
|
[
|
|
484
|
-
[
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
__DEV__ ? {
|
|
488
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
489
|
-
} : void 0
|
|
490
|
-
)
|
|
491
|
-
],
|
|
492
|
-
[
|
|
493
|
-
"numReadonlySignerAccounts",
|
|
494
|
-
umiSerializers.u8(
|
|
495
|
-
__DEV__ ? {
|
|
496
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable"
|
|
497
|
-
} : void 0
|
|
498
|
-
)
|
|
499
|
-
],
|
|
500
|
-
[
|
|
501
|
-
"numReadonlyNonSignerAccounts",
|
|
502
|
-
umiSerializers.u8(
|
|
503
|
-
__DEV__ ? {
|
|
504
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
505
|
-
} : void 0
|
|
506
|
-
)
|
|
507
|
-
]
|
|
547
|
+
["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
|
|
548
|
+
["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
|
|
549
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
|
|
508
550
|
],
|
|
509
|
-
|
|
510
|
-
description:
|
|
511
|
-
}
|
|
551
|
+
{
|
|
552
|
+
description: messageHeaderDescription
|
|
553
|
+
}
|
|
512
554
|
);
|
|
513
555
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
)
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
)
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
}
|
|
543
|
-
]
|
|
544
|
-
]),
|
|
545
|
-
(value) => {
|
|
546
|
-
if (value.addressIndices !== void 0 && value.data !== void 0) {
|
|
547
|
-
return value;
|
|
556
|
+
var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
|
|
557
|
+
var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
|
|
558
|
+
var accountIndicesDescription = __DEV__ ? "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" : "accountIndices";
|
|
559
|
+
var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
|
|
560
|
+
var memoizedGetInstructionEncoder;
|
|
561
|
+
function getInstructionEncoder() {
|
|
562
|
+
if (!memoizedGetInstructionEncoder) {
|
|
563
|
+
memoizedGetInstructionEncoder = codecsCore.mapEncoder(
|
|
564
|
+
codecsDataStructures.getStructEncoder([
|
|
565
|
+
["programAddressIndex", codecsNumbers.getU8Encoder({ description: programAddressIndexDescription })],
|
|
566
|
+
[
|
|
567
|
+
"accountIndices",
|
|
568
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder({ description: accountIndexDescription }), {
|
|
569
|
+
description: accountIndicesDescription,
|
|
570
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
571
|
+
})
|
|
572
|
+
],
|
|
573
|
+
["data", codecsDataStructures.getBytesEncoder({ description: dataDescription, size: codecsNumbers.getShortU16Encoder() })]
|
|
574
|
+
]),
|
|
575
|
+
// Convert an instruction to have all fields defined
|
|
576
|
+
(instruction) => {
|
|
577
|
+
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
578
|
+
return instruction;
|
|
579
|
+
}
|
|
580
|
+
return {
|
|
581
|
+
...instruction,
|
|
582
|
+
accountIndices: instruction.accountIndices ?? [],
|
|
583
|
+
data: instruction.data ?? new Uint8Array(0)
|
|
584
|
+
};
|
|
548
585
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
return memoizedGetInstructionEncoder;
|
|
589
|
+
}
|
|
590
|
+
var memoizedGetInstructionDecoder;
|
|
591
|
+
function getInstructionDecoder() {
|
|
592
|
+
if (!memoizedGetInstructionDecoder) {
|
|
593
|
+
memoizedGetInstructionDecoder = codecsCore.mapDecoder(
|
|
594
|
+
codecsDataStructures.getStructDecoder([
|
|
595
|
+
["programAddressIndex", codecsNumbers.getU8Decoder({ description: programAddressIndexDescription })],
|
|
596
|
+
[
|
|
597
|
+
"accountIndices",
|
|
598
|
+
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder({ description: accountIndexDescription }), {
|
|
599
|
+
description: accountIndicesDescription,
|
|
600
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
601
|
+
})
|
|
602
|
+
],
|
|
603
|
+
["data", codecsDataStructures.getBytesDecoder({ description: dataDescription, size: codecsNumbers.getShortU16Decoder() })]
|
|
604
|
+
]),
|
|
605
|
+
// Convert an instruction to exclude optional fields if they are empty
|
|
606
|
+
(instruction) => {
|
|
607
|
+
if (instruction.accountIndices.length && instruction.data.byteLength) {
|
|
608
|
+
return instruction;
|
|
609
|
+
}
|
|
610
|
+
const { accountIndices, data, ...rest } = instruction;
|
|
611
|
+
return {
|
|
612
|
+
...rest,
|
|
613
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
614
|
+
...data.byteLength ? { data } : null
|
|
615
|
+
};
|
|
558
616
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
...addressIndices.length ? { addressIndices } : null,
|
|
563
|
-
...data.byteLength ? { data } : null
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
// src/serializers/unimplemented.ts
|
|
570
|
-
function getError(type, name) {
|
|
571
|
-
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
572
|
-
return new Error(
|
|
573
|
-
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
|
|
574
|
-
);
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
return memoizedGetInstructionDecoder;
|
|
575
620
|
}
|
|
576
|
-
function
|
|
577
|
-
return ()
|
|
578
|
-
throw getError("decoder", name);
|
|
579
|
-
};
|
|
621
|
+
function getInstructionCodec() {
|
|
622
|
+
return codecsCore.combineCodec(getInstructionEncoder(), getInstructionDecoder());
|
|
580
623
|
}
|
|
581
|
-
|
|
582
|
-
// src/serializers/transaction-version.ts
|
|
583
624
|
var VERSION_FLAG_MASK = 128;
|
|
584
625
|
var BASE_CONFIG = {
|
|
585
626
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
586
627
|
fixedSize: null,
|
|
587
628
|
maxSize: 1
|
|
588
629
|
};
|
|
589
|
-
function
|
|
590
|
-
const firstByte =
|
|
630
|
+
function decode(bytes2, offset = 0) {
|
|
631
|
+
const firstByte = bytes2[offset];
|
|
591
632
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
592
633
|
return ["legacy", offset];
|
|
593
634
|
} else {
|
|
@@ -595,7 +636,7 @@ function deserialize(bytes3, offset = 0) {
|
|
|
595
636
|
return [version, offset + 1];
|
|
596
637
|
}
|
|
597
638
|
}
|
|
598
|
-
function
|
|
639
|
+
function encode(value) {
|
|
599
640
|
if (value === "legacy") {
|
|
600
641
|
return new Uint8Array();
|
|
601
642
|
}
|
|
@@ -604,11 +645,32 @@ function serialize(value) {
|
|
|
604
645
|
}
|
|
605
646
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
606
647
|
}
|
|
607
|
-
function
|
|
648
|
+
function getTransactionVersionDecoder() {
|
|
608
649
|
return {
|
|
609
650
|
...BASE_CONFIG,
|
|
610
|
-
|
|
611
|
-
|
|
651
|
+
decode
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
function getTransactionVersionEncoder() {
|
|
655
|
+
return {
|
|
656
|
+
...BASE_CONFIG,
|
|
657
|
+
encode
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function getTransactionVersionCodec() {
|
|
661
|
+
return codecsCore.combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// src/serializers/unimplemented.ts
|
|
665
|
+
function getError(type, name) {
|
|
666
|
+
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
667
|
+
return new Error(
|
|
668
|
+
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
function getUnimplementedDecoder(name) {
|
|
672
|
+
return () => {
|
|
673
|
+
throw getError("decoder", name);
|
|
612
674
|
};
|
|
613
675
|
}
|
|
614
676
|
|
|
@@ -618,7 +680,7 @@ var BASE_CONFIG2 = {
|
|
|
618
680
|
fixedSize: null,
|
|
619
681
|
maxSize: null
|
|
620
682
|
};
|
|
621
|
-
function
|
|
683
|
+
function serialize(compiledMessage) {
|
|
622
684
|
if (compiledMessage.version === "legacy") {
|
|
623
685
|
return umiSerializers.struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
|
|
624
686
|
} else {
|
|
@@ -639,13 +701,22 @@ function serialize2(compiledMessage) {
|
|
|
639
701
|
).serialize(compiledMessage);
|
|
640
702
|
}
|
|
641
703
|
}
|
|
704
|
+
function toSerializer(codec) {
|
|
705
|
+
return {
|
|
706
|
+
description: codec.description,
|
|
707
|
+
deserialize: codec.decode,
|
|
708
|
+
fixedSize: codec.fixedSize,
|
|
709
|
+
maxSize: codec.maxSize,
|
|
710
|
+
serialize: codec.encode
|
|
711
|
+
};
|
|
712
|
+
}
|
|
642
713
|
function getPreludeStructSerializerTuple() {
|
|
643
714
|
return [
|
|
644
|
-
["version", getTransactionVersionCodec()],
|
|
645
|
-
["header", getMessageHeaderCodec()],
|
|
715
|
+
["version", toSerializer(getTransactionVersionCodec())],
|
|
716
|
+
["header", toSerializer(getMessageHeaderCodec())],
|
|
646
717
|
[
|
|
647
718
|
"staticAccounts",
|
|
648
|
-
umiSerializers.array(
|
|
719
|
+
umiSerializers.array(toSerializer(addresses.getAddressCodec()), {
|
|
649
720
|
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
|
|
650
721
|
size: umiSerializers.shortU16()
|
|
651
722
|
})
|
|
@@ -660,7 +731,7 @@ function getPreludeStructSerializerTuple() {
|
|
|
660
731
|
],
|
|
661
732
|
[
|
|
662
733
|
"instructions",
|
|
663
|
-
umiSerializers.array(getInstructionCodec(), {
|
|
734
|
+
umiSerializers.array(toSerializer(getInstructionCodec()), {
|
|
664
735
|
description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "",
|
|
665
736
|
size: umiSerializers.shortU16()
|
|
666
737
|
})
|
|
@@ -668,7 +739,7 @@ function getPreludeStructSerializerTuple() {
|
|
|
668
739
|
];
|
|
669
740
|
}
|
|
670
741
|
function getAddressTableLookupsSerializer() {
|
|
671
|
-
return umiSerializers.array(getAddressTableLookupCodec(), {
|
|
742
|
+
return umiSerializers.array(toSerializer(getAddressTableLookupCodec()), {
|
|
672
743
|
...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null,
|
|
673
744
|
size: umiSerializers.shortU16()
|
|
674
745
|
});
|
|
@@ -677,49 +748,7 @@ function getCompiledMessageEncoder() {
|
|
|
677
748
|
return {
|
|
678
749
|
...BASE_CONFIG2,
|
|
679
750
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
680
|
-
serialize
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
// src/signatures.ts
|
|
685
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
686
|
-
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
687
|
-
const signature = await keys.signBytes(secretKey, wireMessageBytes);
|
|
688
|
-
return signature;
|
|
689
|
-
}
|
|
690
|
-
async function signTransaction(keyPair, transaction) {
|
|
691
|
-
const compiledMessage = compileMessage(transaction);
|
|
692
|
-
const [signerPublicKey, signature] = await Promise.all([
|
|
693
|
-
keys.getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
|
|
694
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
695
|
-
]);
|
|
696
|
-
const nextSignatures = {
|
|
697
|
-
..."signatures" in transaction ? transaction.signatures : null,
|
|
698
|
-
...{ [signerPublicKey]: signature }
|
|
699
|
-
};
|
|
700
|
-
const out = {
|
|
701
|
-
...transaction,
|
|
702
|
-
signatures: nextSignatures
|
|
703
|
-
};
|
|
704
|
-
Object.freeze(out);
|
|
705
|
-
return out;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
// src/compile-transaction.ts
|
|
709
|
-
function getCompiledTransaction(transaction) {
|
|
710
|
-
const compiledMessage = compileMessage(transaction);
|
|
711
|
-
let signatures;
|
|
712
|
-
if ("signatures" in transaction) {
|
|
713
|
-
signatures = [];
|
|
714
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
715
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
716
|
-
}
|
|
717
|
-
} else {
|
|
718
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
719
|
-
}
|
|
720
|
-
return {
|
|
721
|
-
compiledMessage,
|
|
722
|
-
signatures
|
|
751
|
+
serialize
|
|
723
752
|
};
|
|
724
753
|
}
|
|
725
754
|
|
|
@@ -729,7 +758,7 @@ var BASE_CONFIG3 = {
|
|
|
729
758
|
fixedSize: null,
|
|
730
759
|
maxSize: null
|
|
731
760
|
};
|
|
732
|
-
function
|
|
761
|
+
function serialize2(transaction) {
|
|
733
762
|
const compiledTransaction = getCompiledTransaction(transaction);
|
|
734
763
|
return umiSerializers.struct([
|
|
735
764
|
[
|
|
@@ -746,8 +775,83 @@ function getTransactionEncoder() {
|
|
|
746
775
|
return {
|
|
747
776
|
...BASE_CONFIG3,
|
|
748
777
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
749
|
-
serialize:
|
|
778
|
+
serialize: serialize2
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
782
|
+
try {
|
|
783
|
+
if (
|
|
784
|
+
// Lowest value (64 bytes of zeroes)
|
|
785
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
786
|
+
putativeTransactionSignature.length > 88
|
|
787
|
+
) {
|
|
788
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
789
|
+
}
|
|
790
|
+
const bytes2 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
791
|
+
const numBytes = bytes2.byteLength;
|
|
792
|
+
if (numBytes !== 64) {
|
|
793
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
794
|
+
}
|
|
795
|
+
} catch (e) {
|
|
796
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
797
|
+
cause: e
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
802
|
+
if (
|
|
803
|
+
// Lowest value (64 bytes of zeroes)
|
|
804
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
805
|
+
putativeTransactionSignature.length > 88
|
|
806
|
+
) {
|
|
807
|
+
return false;
|
|
808
|
+
}
|
|
809
|
+
const bytes2 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
810
|
+
const numBytes = bytes2.byteLength;
|
|
811
|
+
if (numBytes !== 64) {
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
return true;
|
|
815
|
+
}
|
|
816
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
817
|
+
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
818
|
+
const signature = await keys.signBytes(secretKey, wireMessageBytes);
|
|
819
|
+
return signature;
|
|
820
|
+
}
|
|
821
|
+
function getSignatureFromTransaction(transaction) {
|
|
822
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
823
|
+
if (!signatureBytes) {
|
|
824
|
+
throw new Error(
|
|
825
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
const transactionSignature2 = umiSerializers.base58.deserialize(signatureBytes)[0];
|
|
829
|
+
return transactionSignature2;
|
|
830
|
+
}
|
|
831
|
+
async function signTransaction(keyPairs, transaction) {
|
|
832
|
+
const compiledMessage = compileMessage(transaction);
|
|
833
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
834
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
835
|
+
keyPairs.map(
|
|
836
|
+
(keyPair) => Promise.all([
|
|
837
|
+
addresses.getAddressFromPublicKey(keyPair.publicKey),
|
|
838
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
839
|
+
])
|
|
840
|
+
)
|
|
841
|
+
);
|
|
842
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
843
|
+
nextSignatures[signerPublicKey] = signature;
|
|
844
|
+
}
|
|
845
|
+
const out = {
|
|
846
|
+
...transaction,
|
|
847
|
+
signatures: nextSignatures
|
|
750
848
|
};
|
|
849
|
+
Object.freeze(out);
|
|
850
|
+
return out;
|
|
851
|
+
}
|
|
852
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
853
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
854
|
+
return putativeTransactionSignature;
|
|
751
855
|
}
|
|
752
856
|
|
|
753
857
|
// src/wire-transaction.ts
|
|
@@ -761,10 +865,18 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
761
865
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
762
866
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
763
867
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
868
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
764
869
|
exports.createTransaction = createTransaction;
|
|
765
870
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
871
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
872
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
873
|
+
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
874
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
766
875
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
767
876
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
768
877
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
769
878
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
770
879
|
exports.signTransaction = signTransaction;
|
|
880
|
+
exports.transactionSignature = transactionSignature;
|
|
881
|
+
//# sourceMappingURL=out.js.map
|
|
882
|
+
//# sourceMappingURL=index.browser.cjs.map
|