@solana/transactions 2.0.0-experimental.dc614af → 2.0.0-experimental.df45965
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/README.md +314 -5
- package/dist/index.browser.cjs +255 -245
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +252 -250
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +768 -717
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +252 -248
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +255 -245
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +252 -250
- 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/accounts.d.ts.map +1 -1
- package/dist/types/blockhash.d.ts +1 -1
- package/dist/types/blockhash.d.ts.map +1 -1
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -1
- package/dist/types/durable-nonce.d.ts +5 -3
- package/dist/types/durable-nonce.d.ts.map +1 -1
- package/dist/types/fee-payer.d.ts +2 -1
- package/dist/types/fee-payer.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/serializers/address-table-lookup.d.ts +5 -3
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -1
- package/dist/types/serializers/header.d.ts +4 -2
- package/dist/types/serializers/header.d.ts.map +1 -1
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts +4 -2
- package/dist/types/serializers/instruction.d.ts.map +1 -1
- package/dist/types/serializers/message.d.ts +4 -4
- package/dist/types/serializers/message.d.ts.map +1 -1
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/dist/types/serializers/transaction-version.d.ts.map +1 -1
- package/dist/types/serializers/transaction.d.ts +5 -4
- package/dist/types/serializers/transaction.d.ts.map +1 -1
- package/dist/types/signatures.d.ts +10 -2
- package/dist/types/signatures.d.ts.map +1 -1
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/wire-transaction.d.ts +2 -2
- package/dist/types/wire-transaction.d.ts.map +1 -1
- package/package.json +19 -13
- package/dist/types/serializers/unimplemented.d.ts +0 -3
- package/dist/types/serializers/unimplemented.d.ts.map +0 -1
package/dist/index.browser.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { base58
|
|
2
|
-
import {
|
|
1
|
+
import { base58 } from '@metaplex-foundation/umi-serializers';
|
|
2
|
+
import { mapEncoder } from '@solana/codecs-core';
|
|
3
|
+
import { getStructEncoder, getArrayEncoder, getBytesEncoder } from '@solana/codecs-data-structures';
|
|
4
|
+
import { getShortU16Encoder, getU8Encoder } from '@solana/codecs-numbers';
|
|
5
|
+
import { getAddressFromPublicKey, getAddressComparator, getAddressEncoder } from '@solana/addresses';
|
|
6
|
+
import { getStringEncoder, getBase58Encoder } from '@solana/codecs-strings';
|
|
3
7
|
import { signBytes } from '@solana/keys';
|
|
4
8
|
|
|
5
9
|
// ../build-scripts/env-shim.ts
|
|
@@ -29,8 +33,8 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
29
33
|
) {
|
|
30
34
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
31
35
|
}
|
|
32
|
-
const
|
|
33
|
-
const numBytes =
|
|
36
|
+
const bytes = base58.serialize(putativeBlockhash);
|
|
37
|
+
const numBytes = bytes.byteLength;
|
|
34
38
|
if (numBytes !== 32) {
|
|
35
39
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
36
40
|
}
|
|
@@ -228,7 +232,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
228
232
|
const shouldReplaceEntry = (
|
|
229
233
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
230
234
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
231
|
-
(addressComparator || (addressComparator =
|
|
235
|
+
(addressComparator || (addressComparator = getAddressComparator()))(
|
|
232
236
|
accountMeta.lookupTableAddress,
|
|
233
237
|
entry.lookupTableAddress
|
|
234
238
|
) < 0
|
|
@@ -334,7 +338,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
334
338
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
335
339
|
return leftIsWritable ? -1 : 1;
|
|
336
340
|
}
|
|
337
|
-
addressComparator || (addressComparator =
|
|
341
|
+
addressComparator || (addressComparator = getAddressComparator());
|
|
338
342
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
339
343
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
340
344
|
} else {
|
|
@@ -363,7 +367,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
363
367
|
entry.readableIndices.push(account.addressIndex);
|
|
364
368
|
}
|
|
365
369
|
}
|
|
366
|
-
return Object.keys(index).sort(
|
|
370
|
+
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
|
|
367
371
|
lookupTableAddress,
|
|
368
372
|
...index[lookupTableAddress]
|
|
369
373
|
}));
|
|
@@ -442,159 +446,124 @@ function compileMessage(transaction) {
|
|
|
442
446
|
version: transaction.version
|
|
443
447
|
};
|
|
444
448
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
449
|
+
|
|
450
|
+
// src/compile-transaction.ts
|
|
451
|
+
function getCompiledTransaction(transaction) {
|
|
452
|
+
const compiledMessage = compileMessage(transaction);
|
|
453
|
+
let signatures;
|
|
454
|
+
if ("signatures" in transaction) {
|
|
455
|
+
signatures = [];
|
|
456
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
457
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
compiledMessage,
|
|
464
|
+
signatures
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
468
|
+
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
469
|
+
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
470
|
+
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";
|
|
471
|
+
var memoizedAddressTableLookupEncoder;
|
|
472
|
+
function getAddressTableLookupEncoder() {
|
|
473
|
+
if (!memoizedAddressTableLookupEncoder) {
|
|
474
|
+
memoizedAddressTableLookupEncoder = getStructEncoder(
|
|
456
475
|
[
|
|
457
|
-
"
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
476
|
+
["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
|
|
477
|
+
[
|
|
478
|
+
"writableIndices",
|
|
479
|
+
getArrayEncoder(getU8Encoder(), {
|
|
480
|
+
description: writableIndicesDescription,
|
|
481
|
+
size: getShortU16Encoder()
|
|
482
|
+
})
|
|
483
|
+
],
|
|
484
|
+
[
|
|
485
|
+
"readableIndices",
|
|
486
|
+
getArrayEncoder(getU8Encoder(), {
|
|
487
|
+
description: readableIndicesDescription,
|
|
488
|
+
size: getShortU16Encoder()
|
|
489
|
+
})
|
|
490
|
+
]
|
|
464
491
|
],
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
__DEV__ ? {
|
|
476
|
-
description: "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"
|
|
477
|
-
} : void 0
|
|
478
|
-
);
|
|
492
|
+
{ description: addressTableLookupDescription }
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
return memoizedAddressTableLookupEncoder;
|
|
496
|
+
}
|
|
497
|
+
var memoizedU8Encoder;
|
|
498
|
+
function getMemoizedU8Encoder() {
|
|
499
|
+
if (!memoizedU8Encoder)
|
|
500
|
+
memoizedU8Encoder = getU8Encoder();
|
|
501
|
+
return memoizedU8Encoder;
|
|
479
502
|
}
|
|
480
|
-
function
|
|
481
|
-
|
|
503
|
+
function getMemoizedU8EncoderDescription(description) {
|
|
504
|
+
const encoder = getMemoizedU8Encoder();
|
|
505
|
+
return {
|
|
506
|
+
...encoder,
|
|
507
|
+
description: description ?? encoder.description
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
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;
|
|
511
|
+
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;
|
|
512
|
+
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
513
|
+
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
514
|
+
function getMessageHeaderEncoder() {
|
|
515
|
+
return getStructEncoder(
|
|
482
516
|
[
|
|
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
|
-
]
|
|
517
|
+
["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
|
|
518
|
+
["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
|
|
519
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
507
520
|
],
|
|
508
|
-
|
|
509
|
-
description:
|
|
510
|
-
} : void 0
|
|
511
|
-
);
|
|
512
|
-
}
|
|
513
|
-
function getInstructionCodec() {
|
|
514
|
-
return mapSerializer(
|
|
515
|
-
struct([
|
|
516
|
-
[
|
|
517
|
-
"programAddressIndex",
|
|
518
|
-
u8(
|
|
519
|
-
__DEV__ ? {
|
|
520
|
-
description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
|
|
521
|
-
} : void 0
|
|
522
|
-
)
|
|
523
|
-
],
|
|
524
|
-
[
|
|
525
|
-
"accountIndices",
|
|
526
|
-
array(
|
|
527
|
-
u8({
|
|
528
|
-
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
529
|
-
}),
|
|
530
|
-
{
|
|
531
|
-
description: __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" : "",
|
|
532
|
-
size: shortU16()
|
|
533
|
-
}
|
|
534
|
-
)
|
|
535
|
-
],
|
|
536
|
-
[
|
|
537
|
-
"data",
|
|
538
|
-
bytes({
|
|
539
|
-
description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
|
|
540
|
-
size: shortU16()
|
|
541
|
-
})
|
|
542
|
-
]
|
|
543
|
-
]),
|
|
544
|
-
(value) => {
|
|
545
|
-
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
546
|
-
return value;
|
|
547
|
-
}
|
|
548
|
-
return {
|
|
549
|
-
...value,
|
|
550
|
-
accountIndices: value.accountIndices ?? [],
|
|
551
|
-
data: value.data ?? new Uint8Array(0)
|
|
552
|
-
};
|
|
553
|
-
},
|
|
554
|
-
(value) => {
|
|
555
|
-
if (value.accountIndices.length && value.data.byteLength) {
|
|
556
|
-
return value;
|
|
557
|
-
}
|
|
558
|
-
const { accountIndices, data, ...rest } = value;
|
|
559
|
-
return {
|
|
560
|
-
...rest,
|
|
561
|
-
...accountIndices.length ? { accountIndices } : null,
|
|
562
|
-
...data.byteLength ? { data } : null
|
|
563
|
-
};
|
|
521
|
+
{
|
|
522
|
+
description: messageHeaderDescription
|
|
564
523
|
}
|
|
565
524
|
);
|
|
566
525
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
)
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
526
|
+
var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
|
|
527
|
+
var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
|
|
528
|
+
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";
|
|
529
|
+
var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
|
|
530
|
+
var memoizedGetInstructionEncoder;
|
|
531
|
+
function getInstructionEncoder() {
|
|
532
|
+
if (!memoizedGetInstructionEncoder) {
|
|
533
|
+
memoizedGetInstructionEncoder = mapEncoder(
|
|
534
|
+
getStructEncoder([
|
|
535
|
+
["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
|
|
536
|
+
[
|
|
537
|
+
"accountIndices",
|
|
538
|
+
getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
|
|
539
|
+
description: accountIndicesDescription,
|
|
540
|
+
size: getShortU16Encoder()
|
|
541
|
+
})
|
|
542
|
+
],
|
|
543
|
+
["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
|
|
544
|
+
]),
|
|
545
|
+
// Convert an instruction to have all fields defined
|
|
546
|
+
(instruction) => {
|
|
547
|
+
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
548
|
+
return instruction;
|
|
549
|
+
}
|
|
550
|
+
return {
|
|
551
|
+
...instruction,
|
|
552
|
+
accountIndices: instruction.accountIndices ?? [],
|
|
553
|
+
data: instruction.data ?? new Uint8Array(0)
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
return memoizedGetInstructionEncoder;
|
|
579
559
|
}
|
|
580
|
-
|
|
581
|
-
// src/serializers/transaction-version.ts
|
|
582
560
|
var VERSION_FLAG_MASK = 128;
|
|
583
561
|
var BASE_CONFIG = {
|
|
584
562
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
585
563
|
fixedSize: null,
|
|
586
564
|
maxSize: 1
|
|
587
565
|
};
|
|
588
|
-
function
|
|
589
|
-
const firstByte = bytes3[offset];
|
|
590
|
-
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
591
|
-
return ["legacy", offset];
|
|
592
|
-
} else {
|
|
593
|
-
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
594
|
-
return [version, offset + 1];
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
function serialize(value) {
|
|
566
|
+
function encode(value) {
|
|
598
567
|
if (value === "legacy") {
|
|
599
568
|
return new Uint8Array();
|
|
600
569
|
}
|
|
@@ -603,99 +572,175 @@ function serialize(value) {
|
|
|
603
572
|
}
|
|
604
573
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
605
574
|
}
|
|
606
|
-
function
|
|
575
|
+
function getTransactionVersionEncoder() {
|
|
607
576
|
return {
|
|
608
577
|
...BASE_CONFIG,
|
|
609
|
-
|
|
610
|
-
serialize
|
|
578
|
+
encode
|
|
611
579
|
};
|
|
612
580
|
}
|
|
613
581
|
|
|
614
582
|
// src/serializers/message.ts
|
|
615
|
-
var
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
(value)
|
|
630
|
-
|
|
631
|
-
return value;
|
|
632
|
-
}
|
|
633
|
-
return {
|
|
634
|
-
...value,
|
|
635
|
-
addressTableLookups: value.addressTableLookups ?? []
|
|
636
|
-
};
|
|
583
|
+
var staticAccountsDescription = __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "staticAccounts";
|
|
584
|
+
var lifetimeTokenDescription = __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "lifetimeToken";
|
|
585
|
+
var instructionsDescription = __DEV__ ? "A compact-array of instructions belonging to this transaction" : "instructions";
|
|
586
|
+
var addressTableLookupsDescription = __DEV__ ? "A compact array of address table lookups belonging to this transaction" : "addressTableLookups";
|
|
587
|
+
function getCompiledMessageLegacyEncoder() {
|
|
588
|
+
return getStructEncoder(getPreludeStructEncoderTuple());
|
|
589
|
+
}
|
|
590
|
+
function getCompiledMessageVersionedEncoder() {
|
|
591
|
+
return mapEncoder(
|
|
592
|
+
getStructEncoder([
|
|
593
|
+
...getPreludeStructEncoderTuple(),
|
|
594
|
+
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
595
|
+
]),
|
|
596
|
+
(value) => {
|
|
597
|
+
if (value.version === "legacy") {
|
|
598
|
+
return value;
|
|
637
599
|
}
|
|
638
|
-
|
|
639
|
-
|
|
600
|
+
return {
|
|
601
|
+
...value,
|
|
602
|
+
addressTableLookups: value.addressTableLookups ?? []
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
);
|
|
640
606
|
}
|
|
641
|
-
function
|
|
607
|
+
function getPreludeStructEncoderTuple() {
|
|
642
608
|
return [
|
|
643
|
-
["version",
|
|
644
|
-
["header",
|
|
609
|
+
["version", getTransactionVersionEncoder()],
|
|
610
|
+
["header", getMessageHeaderEncoder()],
|
|
645
611
|
[
|
|
646
612
|
"staticAccounts",
|
|
647
|
-
|
|
648
|
-
description:
|
|
649
|
-
size:
|
|
613
|
+
getArrayEncoder(getAddressEncoder(), {
|
|
614
|
+
description: staticAccountsDescription,
|
|
615
|
+
size: getShortU16Encoder()
|
|
650
616
|
})
|
|
651
617
|
],
|
|
652
618
|
[
|
|
653
619
|
"lifetimeToken",
|
|
654
|
-
|
|
655
|
-
description:
|
|
656
|
-
encoding:
|
|
620
|
+
getStringEncoder({
|
|
621
|
+
description: lifetimeTokenDescription,
|
|
622
|
+
encoding: getBase58Encoder(),
|
|
657
623
|
size: 32
|
|
658
624
|
})
|
|
659
625
|
],
|
|
660
626
|
[
|
|
661
627
|
"instructions",
|
|
662
|
-
|
|
663
|
-
description:
|
|
664
|
-
size:
|
|
628
|
+
getArrayEncoder(getInstructionEncoder(), {
|
|
629
|
+
description: instructionsDescription,
|
|
630
|
+
size: getShortU16Encoder()
|
|
665
631
|
})
|
|
666
632
|
]
|
|
667
633
|
];
|
|
668
634
|
}
|
|
669
|
-
function
|
|
670
|
-
return
|
|
671
|
-
|
|
672
|
-
size:
|
|
635
|
+
function getAddressTableLookupArrayEncoder() {
|
|
636
|
+
return getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
637
|
+
description: addressTableLookupsDescription,
|
|
638
|
+
size: getShortU16Encoder()
|
|
673
639
|
});
|
|
674
640
|
}
|
|
641
|
+
var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
|
|
675
642
|
function getCompiledMessageEncoder() {
|
|
676
643
|
return {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
644
|
+
description: messageDescription,
|
|
645
|
+
encode: (compiledMessage) => {
|
|
646
|
+
if (compiledMessage.version === "legacy") {
|
|
647
|
+
return getCompiledMessageLegacyEncoder().encode(compiledMessage);
|
|
648
|
+
} else {
|
|
649
|
+
return getCompiledMessageVersionedEncoder().encode(compiledMessage);
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
fixedSize: null,
|
|
653
|
+
maxSize: null
|
|
680
654
|
};
|
|
681
655
|
}
|
|
682
656
|
|
|
683
|
-
// src/
|
|
657
|
+
// src/serializers/transaction.ts
|
|
658
|
+
var transactionDescription = __DEV__ ? "The wire format of a Solana transaction" : "transaction";
|
|
659
|
+
var signaturesDescription = __DEV__ ? "A compact array of 64-byte, base-64 encoded Ed25519 signatures" : "signatures";
|
|
660
|
+
function getCompiledTransactionEncoder() {
|
|
661
|
+
return getStructEncoder(
|
|
662
|
+
[
|
|
663
|
+
[
|
|
664
|
+
"signatures",
|
|
665
|
+
getArrayEncoder(getBytesEncoder({ size: 64 }), {
|
|
666
|
+
description: signaturesDescription,
|
|
667
|
+
size: getShortU16Encoder()
|
|
668
|
+
})
|
|
669
|
+
],
|
|
670
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
671
|
+
],
|
|
672
|
+
{
|
|
673
|
+
description: transactionDescription
|
|
674
|
+
}
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
function getTransactionEncoder() {
|
|
678
|
+
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
679
|
+
}
|
|
680
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
681
|
+
try {
|
|
682
|
+
if (
|
|
683
|
+
// Lowest value (64 bytes of zeroes)
|
|
684
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
685
|
+
putativeTransactionSignature.length > 88
|
|
686
|
+
) {
|
|
687
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
688
|
+
}
|
|
689
|
+
const bytes = base58.serialize(putativeTransactionSignature);
|
|
690
|
+
const numBytes = bytes.byteLength;
|
|
691
|
+
if (numBytes !== 64) {
|
|
692
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
693
|
+
}
|
|
694
|
+
} catch (e) {
|
|
695
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
696
|
+
cause: e
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
701
|
+
if (
|
|
702
|
+
// Lowest value (64 bytes of zeroes)
|
|
703
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
704
|
+
putativeTransactionSignature.length > 88
|
|
705
|
+
) {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
const bytes = base58.serialize(putativeTransactionSignature);
|
|
709
|
+
const numBytes = bytes.byteLength;
|
|
710
|
+
if (numBytes !== 64) {
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
return true;
|
|
714
|
+
}
|
|
684
715
|
async function getCompiledMessageSignature(message, secretKey) {
|
|
685
|
-
const wireMessageBytes = getCompiledMessageEncoder().
|
|
716
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(message);
|
|
686
717
|
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
687
718
|
return signature;
|
|
688
719
|
}
|
|
689
|
-
|
|
720
|
+
function getSignatureFromTransaction(transaction) {
|
|
721
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
722
|
+
if (!signatureBytes) {
|
|
723
|
+
throw new Error(
|
|
724
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
const transactionSignature2 = base58.deserialize(signatureBytes)[0];
|
|
728
|
+
return transactionSignature2;
|
|
729
|
+
}
|
|
730
|
+
async function signTransaction(keyPairs, transaction) {
|
|
690
731
|
const compiledMessage = compileMessage(transaction);
|
|
691
|
-
const
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
732
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
733
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
734
|
+
keyPairs.map(
|
|
735
|
+
(keyPair) => Promise.all([
|
|
736
|
+
getAddressFromPublicKey(keyPair.publicKey),
|
|
737
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
738
|
+
])
|
|
739
|
+
)
|
|
740
|
+
);
|
|
741
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
742
|
+
nextSignatures[signerPublicKey] = signature;
|
|
743
|
+
}
|
|
699
744
|
const out = {
|
|
700
745
|
...transaction,
|
|
701
746
|
signatures: nextSignatures
|
|
@@ -703,60 +748,17 @@ async function signTransaction(keyPair, transaction) {
|
|
|
703
748
|
Object.freeze(out);
|
|
704
749
|
return out;
|
|
705
750
|
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
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
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
// src/serializers/transaction.ts
|
|
726
|
-
var BASE_CONFIG3 = {
|
|
727
|
-
description: __DEV__ ? "The wire format of a Solana transaction" : "",
|
|
728
|
-
fixedSize: null,
|
|
729
|
-
maxSize: null
|
|
730
|
-
};
|
|
731
|
-
function serialize3(transaction) {
|
|
732
|
-
const compiledTransaction = getCompiledTransaction(transaction);
|
|
733
|
-
return struct([
|
|
734
|
-
[
|
|
735
|
-
"signatures",
|
|
736
|
-
array(bytes({ size: 64 }), {
|
|
737
|
-
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
|
|
738
|
-
size: shortU16()
|
|
739
|
-
})
|
|
740
|
-
],
|
|
741
|
-
["compiledMessage", getCompiledMessageEncoder()]
|
|
742
|
-
]).serialize(compiledTransaction);
|
|
743
|
-
}
|
|
744
|
-
function getTransactionEncoder() {
|
|
745
|
-
return {
|
|
746
|
-
...BASE_CONFIG3,
|
|
747
|
-
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
748
|
-
serialize: serialize3
|
|
749
|
-
};
|
|
751
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
752
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
753
|
+
return putativeTransactionSignature;
|
|
750
754
|
}
|
|
751
755
|
|
|
752
756
|
// src/wire-transaction.ts
|
|
753
757
|
function getBase64EncodedWireTransaction(transaction) {
|
|
754
|
-
const wireTransactionBytes = getTransactionEncoder().
|
|
758
|
+
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
755
759
|
{
|
|
756
760
|
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
757
761
|
}
|
|
758
762
|
}
|
|
759
763
|
|
|
760
|
-
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, createTransaction, getBase64EncodedWireTransaction, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction };
|
|
761
|
-
//# sourceMappingURL=out.js.map
|
|
762
|
-
//# sourceMappingURL=index.browser.js.map
|
|
764
|
+
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isAdvanceNonceAccountInstruction, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature };
|