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