@solana/web3.js 1.58.0 → 1.59.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 +89 -5
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +89 -4
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +89 -5
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +23 -0
- package/lib/index.esm.js +89 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +343 -703
- 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 +89 -5
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -2
- package/src/layout.ts +22 -0
- package/src/programs/secp256k1.ts +5 -7
- package/src/programs/vote.ts +109 -2
package/lib/index.cjs.js
CHANGED
|
@@ -17,7 +17,7 @@ var RpcClient = require('jayson/lib/client/browser');
|
|
|
17
17
|
var http = require('http');
|
|
18
18
|
var https = require('https');
|
|
19
19
|
var nodeFetch = require('node-fetch');
|
|
20
|
-
var sha3 = require('
|
|
20
|
+
var sha3 = require('@noble/hashes/sha3');
|
|
21
21
|
var hmac = require('@noble/hashes/hmac');
|
|
22
22
|
var secp256k1 = require('@noble/secp256k1');
|
|
23
23
|
|
|
@@ -49,7 +49,6 @@ var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
|
|
|
49
49
|
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
50
50
|
var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
|
|
51
51
|
var nodeFetch__namespace = /*#__PURE__*/_interopNamespace(nodeFetch);
|
|
52
|
-
var sha3__default = /*#__PURE__*/_interopDefaultLegacy(sha3);
|
|
53
52
|
var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
|
|
54
53
|
|
|
55
54
|
/**
|
|
@@ -523,7 +522,6 @@ class MessageAccountKeys {
|
|
|
523
522
|
/**
|
|
524
523
|
* Layout for a public key
|
|
525
524
|
*/
|
|
526
|
-
|
|
527
525
|
const publicKey = (property = 'publicKey') => {
|
|
528
526
|
return BufferLayout__namespace.blob(32, property);
|
|
529
527
|
};
|
|
@@ -587,6 +585,13 @@ const lockup = (property = 'lockup') => {
|
|
|
587
585
|
const voteInit = (property = 'voteInit') => {
|
|
588
586
|
return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
|
|
589
587
|
};
|
|
588
|
+
/**
|
|
589
|
+
* Layout for a VoteAuthorizeWithSeedArgs object
|
|
590
|
+
*/
|
|
591
|
+
|
|
592
|
+
const voteAuthorizeWithSeedArgs = (property = 'voteAuthorizeWithSeedArgs') => {
|
|
593
|
+
return BufferLayout__namespace.struct([BufferLayout__namespace.u32('voteAuthorizationType'), publicKey('currentAuthorityDerivedKeyOwnerPubkey'), rustString('currentAuthorityDerivedKeySeed'), publicKey('newAuthorized')], property);
|
|
594
|
+
};
|
|
590
595
|
function getAlloc(type, fields) {
|
|
591
596
|
const getItemAlloc = item => {
|
|
592
597
|
if (item.span >= 0) {
|
|
@@ -599,6 +604,11 @@ function getAlloc(type, fields) {
|
|
|
599
604
|
if (Array.isArray(field)) {
|
|
600
605
|
return field.length * getItemAlloc(item.elementLayout);
|
|
601
606
|
}
|
|
607
|
+
} else if ('fields' in item) {
|
|
608
|
+
// This is a `Structure` whose size needs to be recursively measured.
|
|
609
|
+
return getAlloc({
|
|
610
|
+
layout: item
|
|
611
|
+
}, fields[item.property]);
|
|
602
612
|
} // Couldn't determine allocated size of layout
|
|
603
613
|
|
|
604
614
|
|
|
@@ -8130,7 +8140,7 @@ class Secp256k1Program {
|
|
|
8130
8140
|
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8131
8141
|
|
|
8132
8142
|
try {
|
|
8133
|
-
return buffer.Buffer.from(
|
|
8143
|
+
return buffer.Buffer.from(sha3.keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8134
8144
|
} catch (error) {
|
|
8135
8145
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8136
8146
|
}
|
|
@@ -8230,7 +8240,7 @@ class Secp256k1Program {
|
|
|
8230
8240
|
/* isCompressed */
|
|
8231
8241
|
).slice(1); // throw away leading byte
|
|
8232
8242
|
|
|
8233
|
-
const messageHash = buffer.Buffer.from(
|
|
8243
|
+
const messageHash = buffer.Buffer.from(sha3.keccak_256(toBuffer(message)));
|
|
8234
8244
|
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
8235
8245
|
return this.createInstructionWithPublicKey({
|
|
8236
8246
|
publicKey,
|
|
@@ -9124,6 +9134,33 @@ class VoteInstruction {
|
|
|
9124
9134
|
}
|
|
9125
9135
|
};
|
|
9126
9136
|
}
|
|
9137
|
+
/**
|
|
9138
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
9139
|
+
*/
|
|
9140
|
+
|
|
9141
|
+
|
|
9142
|
+
static decodeAuthorizeWithSeed(instruction) {
|
|
9143
|
+
this.checkProgramId(instruction.programId);
|
|
9144
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
9145
|
+
const {
|
|
9146
|
+
voteAuthorizeWithSeedArgs: {
|
|
9147
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9148
|
+
currentAuthorityDerivedKeySeed,
|
|
9149
|
+
newAuthorized,
|
|
9150
|
+
voteAuthorizationType
|
|
9151
|
+
}
|
|
9152
|
+
} = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
|
|
9153
|
+
return {
|
|
9154
|
+
currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
|
|
9155
|
+
currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
|
|
9156
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9157
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
9158
|
+
voteAuthorizationType: {
|
|
9159
|
+
index: voteAuthorizationType
|
|
9160
|
+
},
|
|
9161
|
+
votePubkey: instruction.keys[0].pubkey
|
|
9162
|
+
};
|
|
9163
|
+
}
|
|
9127
9164
|
/**
|
|
9128
9165
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
9129
9166
|
*/
|
|
@@ -9180,6 +9217,10 @@ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
9180
9217
|
Withdraw: {
|
|
9181
9218
|
index: 3,
|
|
9182
9219
|
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports')])
|
|
9220
|
+
},
|
|
9221
|
+
AuthorizeWithSeed: {
|
|
9222
|
+
index: 10,
|
|
9223
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), voteAuthorizeWithSeedArgs()])
|
|
9183
9224
|
}
|
|
9184
9225
|
});
|
|
9185
9226
|
/**
|
|
@@ -9308,6 +9349,49 @@ class VoteProgram {
|
|
|
9308
9349
|
data
|
|
9309
9350
|
});
|
|
9310
9351
|
}
|
|
9352
|
+
/**
|
|
9353
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
9354
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
9355
|
+
*/
|
|
9356
|
+
|
|
9357
|
+
|
|
9358
|
+
static authorizeWithSeed(params) {
|
|
9359
|
+
const {
|
|
9360
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
9361
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
9362
|
+
currentAuthorityDerivedKeySeed,
|
|
9363
|
+
newAuthorizedPubkey,
|
|
9364
|
+
voteAuthorizationType,
|
|
9365
|
+
votePubkey
|
|
9366
|
+
} = params;
|
|
9367
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
9368
|
+
const data = encodeData(type, {
|
|
9369
|
+
voteAuthorizeWithSeedArgs: {
|
|
9370
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
|
|
9371
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
9372
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
9373
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
9374
|
+
}
|
|
9375
|
+
});
|
|
9376
|
+
const keys = [{
|
|
9377
|
+
pubkey: votePubkey,
|
|
9378
|
+
isSigner: false,
|
|
9379
|
+
isWritable: true
|
|
9380
|
+
}, {
|
|
9381
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
9382
|
+
isSigner: false,
|
|
9383
|
+
isWritable: false
|
|
9384
|
+
}, {
|
|
9385
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
9386
|
+
isSigner: true,
|
|
9387
|
+
isWritable: false
|
|
9388
|
+
}];
|
|
9389
|
+
return new Transaction().add({
|
|
9390
|
+
keys,
|
|
9391
|
+
programId: this.programId,
|
|
9392
|
+
data
|
|
9393
|
+
});
|
|
9394
|
+
}
|
|
9311
9395
|
/**
|
|
9312
9396
|
* Generate a transaction to withdraw from a Vote account.
|
|
9313
9397
|
*/
|