@solana/web3.js 1.58.0 → 1.60.0
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/lib/index.browser.cjs.js +103 -24
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +103 -23
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +103 -24
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +27 -2
- package/lib/index.esm.js +103 -23
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +357 -722
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +5 -13
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +103 -24
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -2
- package/src/connection.ts +5 -0
- package/src/keypair.ts +1 -1
- package/src/layout.ts +22 -0
- package/src/programs/secp256k1.ts +5 -7
- package/src/programs/vote.ts +109 -2
- package/src/transaction/message.ts +15 -24
package/lib/index.native.js
CHANGED
|
@@ -14,7 +14,7 @@ var bigintBuffer = require('bigint-buffer');
|
|
|
14
14
|
var superstruct = require('superstruct');
|
|
15
15
|
var rpcWebsockets = require('rpc-websockets');
|
|
16
16
|
var RpcClient = require('jayson/lib/client/browser');
|
|
17
|
-
var sha3 = require('
|
|
17
|
+
var sha3 = require('@noble/hashes/sha3');
|
|
18
18
|
var hmac = require('@noble/hashes/hmac');
|
|
19
19
|
var secp256k1 = require('@noble/secp256k1');
|
|
20
20
|
|
|
@@ -43,7 +43,6 @@ var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
|
|
|
43
43
|
var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
44
44
|
var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
|
|
45
45
|
var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
|
|
46
|
-
var sha3__default = /*#__PURE__*/_interopDefaultLegacy(sha3);
|
|
47
46
|
var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
|
|
48
47
|
|
|
49
48
|
/**
|
|
@@ -517,7 +516,6 @@ class MessageAccountKeys {
|
|
|
517
516
|
/**
|
|
518
517
|
* Layout for a public key
|
|
519
518
|
*/
|
|
520
|
-
|
|
521
519
|
const publicKey = (property = 'publicKey') => {
|
|
522
520
|
return BufferLayout__namespace.blob(32, property);
|
|
523
521
|
};
|
|
@@ -581,6 +579,13 @@ const lockup = (property = 'lockup') => {
|
|
|
581
579
|
const voteInit = (property = 'voteInit') => {
|
|
582
580
|
return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
|
|
583
581
|
};
|
|
582
|
+
/**
|
|
583
|
+
* Layout for a VoteAuthorizeWithSeedArgs object
|
|
584
|
+
*/
|
|
585
|
+
|
|
586
|
+
const voteAuthorizeWithSeedArgs = (property = 'voteAuthorizeWithSeedArgs') => {
|
|
587
|
+
return BufferLayout__namespace.struct([BufferLayout__namespace.u32('voteAuthorizationType'), publicKey('currentAuthorityDerivedKeyOwnerPubkey'), rustString('currentAuthorityDerivedKeySeed'), publicKey('newAuthorized')], property);
|
|
588
|
+
};
|
|
584
589
|
function getAlloc(type, fields) {
|
|
585
590
|
const getItemAlloc = item => {
|
|
586
591
|
if (item.span >= 0) {
|
|
@@ -593,6 +598,11 @@ function getAlloc(type, fields) {
|
|
|
593
598
|
if (Array.isArray(field)) {
|
|
594
599
|
return field.length * getItemAlloc(item.elementLayout);
|
|
595
600
|
}
|
|
601
|
+
} else if ('fields' in item) {
|
|
602
|
+
// This is a `Structure` whose size needs to be recursively measured.
|
|
603
|
+
return getAlloc({
|
|
604
|
+
layout: item
|
|
605
|
+
}, fields[item.property]);
|
|
596
606
|
} // Couldn't determine allocated size of layout
|
|
597
607
|
|
|
598
608
|
|
|
@@ -1962,10 +1972,10 @@ class Transaction {
|
|
|
1962
1972
|
|
|
1963
1973
|
class TransactionMessage {
|
|
1964
1974
|
constructor(args) {
|
|
1965
|
-
this.
|
|
1975
|
+
this.payerKey = void 0;
|
|
1966
1976
|
this.instructions = void 0;
|
|
1967
1977
|
this.recentBlockhash = void 0;
|
|
1968
|
-
this.
|
|
1978
|
+
this.payerKey = args.payerKey;
|
|
1969
1979
|
this.instructions = args.instructions;
|
|
1970
1980
|
this.recentBlockhash = args.recentBlockhash;
|
|
1971
1981
|
}
|
|
@@ -1986,6 +1996,12 @@ class TransactionMessage {
|
|
|
1986
1996
|
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1987
1997
|
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1988
1998
|
const accountKeys = message.getAccountKeys(args);
|
|
1999
|
+
const payerKey = accountKeys.get(0);
|
|
2000
|
+
|
|
2001
|
+
if (payerKey === undefined) {
|
|
2002
|
+
throw new Error('Failed to decompile message because no account keys were found');
|
|
2003
|
+
}
|
|
2004
|
+
|
|
1989
2005
|
const instructions = [];
|
|
1990
2006
|
|
|
1991
2007
|
for (const compiledIx of compiledInstructions) {
|
|
@@ -2031,35 +2047,23 @@ class TransactionMessage {
|
|
|
2031
2047
|
}
|
|
2032
2048
|
|
|
2033
2049
|
return new TransactionMessage({
|
|
2034
|
-
|
|
2050
|
+
payerKey,
|
|
2035
2051
|
instructions,
|
|
2036
2052
|
recentBlockhash
|
|
2037
2053
|
});
|
|
2038
2054
|
}
|
|
2039
2055
|
|
|
2040
2056
|
compileToLegacyMessage() {
|
|
2041
|
-
const payerKey = this.accountKeys.get(0);
|
|
2042
|
-
|
|
2043
|
-
if (payerKey === undefined) {
|
|
2044
|
-
throw new Error('Failed to compile message because no account keys were found');
|
|
2045
|
-
}
|
|
2046
|
-
|
|
2047
2057
|
return Message.compile({
|
|
2048
|
-
payerKey,
|
|
2058
|
+
payerKey: this.payerKey,
|
|
2049
2059
|
recentBlockhash: this.recentBlockhash,
|
|
2050
2060
|
instructions: this.instructions
|
|
2051
2061
|
});
|
|
2052
2062
|
}
|
|
2053
2063
|
|
|
2054
2064
|
compileToV0Message(addressLookupTableAccounts) {
|
|
2055
|
-
const payerKey = this.accountKeys.get(0);
|
|
2056
|
-
|
|
2057
|
-
if (payerKey === undefined) {
|
|
2058
|
-
throw new Error('Failed to compile message because no account keys were found');
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
2065
|
return MessageV0.compile({
|
|
2062
|
-
payerKey,
|
|
2066
|
+
payerKey: this.payerKey,
|
|
2063
2067
|
recentBlockhash: this.recentBlockhash,
|
|
2064
2068
|
instructions: this.instructions,
|
|
2065
2069
|
addressLookupTableAccounts
|
|
@@ -4295,7 +4299,8 @@ const ParsedConfirmedTransactionResult = superstruct.type({
|
|
|
4295
4299
|
accountKeys: superstruct.array(superstruct.type({
|
|
4296
4300
|
pubkey: PublicKeyFromString,
|
|
4297
4301
|
signer: superstruct.boolean(),
|
|
4298
|
-
writable: superstruct.boolean()
|
|
4302
|
+
writable: superstruct.boolean(),
|
|
4303
|
+
source: superstruct.optional(superstruct.union([superstruct.literal('transaction'), superstruct.literal('lookupTable')]))
|
|
4299
4304
|
})),
|
|
4300
4305
|
instructions: superstruct.array(ParsedOrRawInstruction),
|
|
4301
4306
|
recentBlockhash: superstruct.string(),
|
|
@@ -7471,7 +7476,7 @@ class Keypair {
|
|
|
7471
7476
|
|
|
7472
7477
|
|
|
7473
7478
|
get secretKey() {
|
|
7474
|
-
return this._keypair.secretKey;
|
|
7479
|
+
return new Uint8Array(this._keypair.secretKey);
|
|
7475
7480
|
}
|
|
7476
7481
|
|
|
7477
7482
|
}
|
|
@@ -8064,7 +8069,7 @@ class Secp256k1Program {
|
|
|
8064
8069
|
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8065
8070
|
|
|
8066
8071
|
try {
|
|
8067
|
-
return buffer.Buffer.from(
|
|
8072
|
+
return buffer.Buffer.from(sha3.keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8068
8073
|
} catch (error) {
|
|
8069
8074
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8070
8075
|
}
|
|
@@ -8164,7 +8169,7 @@ class Secp256k1Program {
|
|
|
8164
8169
|
/* isCompressed */
|
|
8165
8170
|
).slice(1); // throw away leading byte
|
|
8166
8171
|
|
|
8167
|
-
const messageHash = buffer.Buffer.from(
|
|
8172
|
+
const messageHash = buffer.Buffer.from(sha3.keccak_256(toBuffer(message)));
|
|
8168
8173
|
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
8169
8174
|
return this.createInstructionWithPublicKey({
|
|
8170
8175
|
publicKey,
|
|
@@ -9058,6 +9063,33 @@ class VoteInstruction {
|
|
|
9058
9063
|
}
|
|
9059
9064
|
};
|
|
9060
9065
|
}
|
|
9066
|
+
/**
|
|
9067
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
9068
|
+
*/
|
|
9069
|
+
|
|
9070
|
+
|
|
9071
|
+
static decodeAuthorizeWithSeed(instruction) {
|
|
9072
|
+
this.checkProgramId(instruction.programId);
|
|
9073
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
9074
|
+
const {
|
|
9075
|
+
voteAuthorizeWithSeedArgs: {
|
|
9076
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9077
|
+
currentAuthorityDerivedKeySeed,
|
|
9078
|
+
newAuthorized,
|
|
9079
|
+
voteAuthorizationType
|
|
9080
|
+
}
|
|
9081
|
+
} = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
|
|
9082
|
+
return {
|
|
9083
|
+
currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
|
|
9084
|
+
currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
|
|
9085
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9086
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
9087
|
+
voteAuthorizationType: {
|
|
9088
|
+
index: voteAuthorizationType
|
|
9089
|
+
},
|
|
9090
|
+
votePubkey: instruction.keys[0].pubkey
|
|
9091
|
+
};
|
|
9092
|
+
}
|
|
9061
9093
|
/**
|
|
9062
9094
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
9063
9095
|
*/
|
|
@@ -9114,6 +9146,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
9114
9146
|
Withdraw: {
|
|
9115
9147
|
index: 3,
|
|
9116
9148
|
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports')])
|
|
9149
|
+
},
|
|
9150
|
+
AuthorizeWithSeed: {
|
|
9151
|
+
index: 10,
|
|
9152
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), voteAuthorizeWithSeedArgs()])
|
|
9117
9153
|
}
|
|
9118
9154
|
});
|
|
9119
9155
|
/**
|
|
@@ -9242,6 +9278,49 @@ class VoteProgram {
|
|
|
9242
9278
|
data
|
|
9243
9279
|
});
|
|
9244
9280
|
}
|
|
9281
|
+
/**
|
|
9282
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
9283
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
9284
|
+
*/
|
|
9285
|
+
|
|
9286
|
+
|
|
9287
|
+
static authorizeWithSeed(params) {
|
|
9288
|
+
const {
|
|
9289
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
9290
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9291
|
+
currentAuthorityDerivedKeySeed,
|
|
9292
|
+
newAuthorizedPubkey,
|
|
9293
|
+
voteAuthorizationType,
|
|
9294
|
+
votePubkey
|
|
9295
|
+
} = params;
|
|
9296
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
9297
|
+
const data = encodeData(type, {
|
|
9298
|
+
voteAuthorizeWithSeedArgs: {
|
|
9299
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
|
|
9300
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9301
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
9302
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
9303
|
+
}
|
|
9304
|
+
});
|
|
9305
|
+
const keys = [{
|
|
9306
|
+
pubkey: votePubkey,
|
|
9307
|
+
isSigner: false,
|
|
9308
|
+
isWritable: true
|
|
9309
|
+
}, {
|
|
9310
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
9311
|
+
isSigner: false,
|
|
9312
|
+
isWritable: false
|
|
9313
|
+
}, {
|
|
9314
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
9315
|
+
isSigner: true,
|
|
9316
|
+
isWritable: false
|
|
9317
|
+
}];
|
|
9318
|
+
return new Transaction().add({
|
|
9319
|
+
keys,
|
|
9320
|
+
programId: this.programId,
|
|
9321
|
+
data
|
|
9322
|
+
});
|
|
9323
|
+
}
|
|
9245
9324
|
/**
|
|
9246
9325
|
* Generate a transaction to withdraw from a Vote account.
|
|
9247
9326
|
*/
|