@solana/web3.js 1.75.0 → 1.76.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 +47 -62
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +12 -23
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +61 -76
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +12 -23
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +3106 -1753
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +12 -5
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +47 -62
- package/lib/index.native.js.map +1 -1
- package/package.json +12 -13
- package/src/utils/ed25519.ts +6 -9
- package/src/utils/secp256k1.ts +7 -14
package/lib/index.browser.cjs.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var buffer = require('buffer');
|
|
6
|
-
var
|
|
7
|
-
var ed25519 = require('@noble/ed25519');
|
|
4
|
+
var ed25519 = require('@noble/curves/ed25519');
|
|
8
5
|
var BN = require('bn.js');
|
|
9
6
|
var bs58 = require('bs58');
|
|
10
7
|
var sha256 = require('@noble/hashes/sha256');
|
|
@@ -16,13 +13,12 @@ var RpcClient = require('jayson/lib/client/browser');
|
|
|
16
13
|
var RpcWebSocketCommonClient = require('rpc-websockets/dist/lib/client');
|
|
17
14
|
var createRpc = require('rpc-websockets/dist/lib/client/websocket.browser');
|
|
18
15
|
var sha3 = require('@noble/hashes/sha3');
|
|
19
|
-
var
|
|
20
|
-
var secp256k1 = require('@noble/secp256k1');
|
|
16
|
+
var secp256k1 = require('@noble/curves/secp256k1');
|
|
21
17
|
|
|
22
|
-
function
|
|
18
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
23
19
|
|
|
24
|
-
function
|
|
25
|
-
if (e && e
|
|
20
|
+
function _interopNamespaceCompat(e) {
|
|
21
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
26
22
|
var n = Object.create(null);
|
|
27
23
|
if (e) {
|
|
28
24
|
Object.keys(e).forEach(function (k) {
|
|
@@ -35,18 +31,16 @@ function _interopNamespace(e) {
|
|
|
35
31
|
}
|
|
36
32
|
});
|
|
37
33
|
}
|
|
38
|
-
n
|
|
34
|
+
n.default = e;
|
|
39
35
|
return Object.freeze(n);
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var createRpc__default = /*#__PURE__*/_interopDefaultLegacy(createRpc);
|
|
49
|
-
var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
|
|
38
|
+
var BN__default = /*#__PURE__*/_interopDefaultCompat(BN);
|
|
39
|
+
var bs58__default = /*#__PURE__*/_interopDefaultCompat(bs58);
|
|
40
|
+
var BufferLayout__namespace = /*#__PURE__*/_interopNamespaceCompat(BufferLayout);
|
|
41
|
+
var RpcClient__default = /*#__PURE__*/_interopDefaultCompat(RpcClient);
|
|
42
|
+
var RpcWebSocketCommonClient__default = /*#__PURE__*/_interopDefaultCompat(RpcWebSocketCommonClient);
|
|
43
|
+
var createRpc__default = /*#__PURE__*/_interopDefaultCompat(createRpc);
|
|
50
44
|
|
|
51
45
|
/**
|
|
52
46
|
* A 64 byte secret key, the first 32 bytes of which is the
|
|
@@ -54,10 +48,9 @@ var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
|
|
|
54
48
|
* Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
|
|
55
49
|
*/
|
|
56
50
|
|
|
57
|
-
|
|
58
|
-
const generatePrivateKey = ed25519__namespace.utils.randomPrivateKey;
|
|
51
|
+
const generatePrivateKey = ed25519.ed25519.utils.randomPrivateKey;
|
|
59
52
|
const generateKeypair = () => {
|
|
60
|
-
const privateScalar =
|
|
53
|
+
const privateScalar = ed25519.ed25519.utils.randomPrivateKey();
|
|
61
54
|
const publicKey = getPublicKey(privateScalar);
|
|
62
55
|
const secretKey = new Uint8Array(64);
|
|
63
56
|
secretKey.set(privateScalar);
|
|
@@ -67,17 +60,17 @@ const generateKeypair = () => {
|
|
|
67
60
|
secretKey
|
|
68
61
|
};
|
|
69
62
|
};
|
|
70
|
-
const getPublicKey =
|
|
63
|
+
const getPublicKey = ed25519.ed25519.getPublicKey;
|
|
71
64
|
function isOnCurve(publicKey) {
|
|
72
65
|
try {
|
|
73
|
-
|
|
66
|
+
ed25519.ed25519.ExtendedPoint.fromHex(publicKey);
|
|
74
67
|
return true;
|
|
75
68
|
} catch {
|
|
76
69
|
return false;
|
|
77
70
|
}
|
|
78
71
|
}
|
|
79
|
-
const sign = (message, secretKey) =>
|
|
80
|
-
const verify =
|
|
72
|
+
const sign = (message, secretKey) => ed25519.ed25519.sign(message, secretKey.slice(0, 32));
|
|
73
|
+
const verify = ed25519.ed25519.verify;
|
|
81
74
|
|
|
82
75
|
const toBuffer = arr => {
|
|
83
76
|
if (buffer.Buffer.isBuffer(arr)) {
|
|
@@ -163,13 +156,13 @@ class PublicKey extends Struct {
|
|
|
163
156
|
} else {
|
|
164
157
|
if (typeof value === 'string') {
|
|
165
158
|
// assume base 58 encoding by default
|
|
166
|
-
const decoded = bs58__default
|
|
159
|
+
const decoded = bs58__default.default.decode(value);
|
|
167
160
|
if (decoded.length != PUBLIC_KEY_LENGTH) {
|
|
168
161
|
throw new Error(`Invalid public key input`);
|
|
169
162
|
}
|
|
170
|
-
this._bn = new BN__default
|
|
163
|
+
this._bn = new BN__default.default(decoded);
|
|
171
164
|
} else {
|
|
172
|
-
this._bn = new BN__default
|
|
165
|
+
this._bn = new BN__default.default(value);
|
|
173
166
|
}
|
|
174
167
|
if (this._bn.byteLength() > PUBLIC_KEY_LENGTH) {
|
|
175
168
|
throw new Error(`Invalid public key input`);
|
|
@@ -202,7 +195,7 @@ class PublicKey extends Struct {
|
|
|
202
195
|
* Return the base-58 representation of the public key
|
|
203
196
|
*/
|
|
204
197
|
toBase58() {
|
|
205
|
-
return bs58__default
|
|
198
|
+
return bs58__default.default.encode(this.toBytes());
|
|
206
199
|
}
|
|
207
200
|
toJSON() {
|
|
208
201
|
return this.toBase58();
|
|
@@ -634,8 +627,8 @@ class CompiledKeys {
|
|
|
634
627
|
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
635
628
|
for (const accountMeta of ix.keys) {
|
|
636
629
|
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
637
|
-
keyMeta.isSigner
|
|
638
|
-
keyMeta.isWritable
|
|
630
|
+
keyMeta.isSigner ||= accountMeta.isSigner;
|
|
631
|
+
keyMeta.isWritable ||= accountMeta.isWritable;
|
|
639
632
|
}
|
|
640
633
|
}
|
|
641
634
|
return new CompiledKeys(payer, keyMetaMap);
|
|
@@ -734,7 +727,7 @@ class Message {
|
|
|
734
727
|
return this.instructions.map(ix => ({
|
|
735
728
|
programIdIndex: ix.programIdIndex,
|
|
736
729
|
accountKeyIndexes: ix.accounts,
|
|
737
|
-
data: bs58__default
|
|
730
|
+
data: bs58__default.default.decode(ix.data)
|
|
738
731
|
}));
|
|
739
732
|
}
|
|
740
733
|
get addressTableLookups() {
|
|
@@ -750,7 +743,7 @@ class Message {
|
|
|
750
743
|
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
751
744
|
programIdIndex: ix.programIdIndex,
|
|
752
745
|
accounts: ix.accountKeyIndexes,
|
|
753
|
-
data: bs58__default
|
|
746
|
+
data: bs58__default.default.encode(ix.data)
|
|
754
747
|
}));
|
|
755
748
|
return new Message({
|
|
756
749
|
header,
|
|
@@ -792,7 +785,7 @@ class Message {
|
|
|
792
785
|
accounts,
|
|
793
786
|
programIdIndex
|
|
794
787
|
} = instruction;
|
|
795
|
-
const data = Array.from(bs58__default
|
|
788
|
+
const data = Array.from(bs58__default.default.decode(instruction.data));
|
|
796
789
|
let keyIndicesCount = [];
|
|
797
790
|
encodeLength(keyIndicesCount, accounts.length);
|
|
798
791
|
let dataCount = [];
|
|
@@ -823,7 +816,7 @@ class Message {
|
|
|
823
816
|
numReadonlyUnsignedAccounts: buffer.Buffer.from([this.header.numReadonlyUnsignedAccounts]),
|
|
824
817
|
keyCount: buffer.Buffer.from(keyCount),
|
|
825
818
|
keys: this.accountKeys.map(key => toBuffer(key.toBytes())),
|
|
826
|
-
recentBlockhash: bs58__default
|
|
819
|
+
recentBlockhash: bs58__default.default.decode(this.recentBlockhash)
|
|
827
820
|
};
|
|
828
821
|
let signData = buffer.Buffer.alloc(2048);
|
|
829
822
|
const length = signDataLayout.encode(transaction, signData);
|
|
@@ -861,7 +854,7 @@ class Message {
|
|
|
861
854
|
byteArray = byteArray.slice(accountCount);
|
|
862
855
|
const dataLength = decodeLength(byteArray);
|
|
863
856
|
const dataSlice = byteArray.slice(0, dataLength);
|
|
864
|
-
const data = bs58__default
|
|
857
|
+
const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
|
|
865
858
|
byteArray = byteArray.slice(dataLength);
|
|
866
859
|
instructions.push({
|
|
867
860
|
programIdIndex,
|
|
@@ -875,7 +868,7 @@ class Message {
|
|
|
875
868
|
numReadonlySignedAccounts,
|
|
876
869
|
numReadonlyUnsignedAccounts
|
|
877
870
|
},
|
|
878
|
-
recentBlockhash: bs58__default
|
|
871
|
+
recentBlockhash: bs58__default.default.encode(buffer.Buffer.from(recentBlockhash)),
|
|
879
872
|
accountKeys,
|
|
880
873
|
instructions
|
|
881
874
|
};
|
|
@@ -1019,7 +1012,7 @@ class MessageV0 {
|
|
|
1019
1012
|
header: this.header,
|
|
1020
1013
|
staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
|
|
1021
1014
|
staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
|
|
1022
|
-
recentBlockhash: bs58__default
|
|
1015
|
+
recentBlockhash: bs58__default.default.decode(this.recentBlockhash),
|
|
1023
1016
|
instructionsLength: new Uint8Array(encodedInstructionsLength),
|
|
1024
1017
|
serializedInstructions,
|
|
1025
1018
|
addressTableLookupsLength: new Uint8Array(encodedAddressTableLookupsLength),
|
|
@@ -1082,7 +1075,7 @@ class MessageV0 {
|
|
|
1082
1075
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1083
1076
|
staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
|
|
1084
1077
|
}
|
|
1085
|
-
const recentBlockhash = bs58__default
|
|
1078
|
+
const recentBlockhash = bs58__default.default.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
|
|
1086
1079
|
const instructionCount = decodeLength(byteArray);
|
|
1087
1080
|
const compiledInstructions = [];
|
|
1088
1081
|
for (let i = 0; i < instructionCount; i++) {
|
|
@@ -1488,7 +1481,7 @@ class Transaction {
|
|
|
1488
1481
|
return {
|
|
1489
1482
|
programIdIndex: accountKeys.indexOf(programId.toString()),
|
|
1490
1483
|
accounts: instruction.keys.map(meta => accountKeys.indexOf(meta.pubkey.toString())),
|
|
1491
|
-
data: bs58__default
|
|
1484
|
+
data: bs58__default.default.encode(data)
|
|
1492
1485
|
};
|
|
1493
1486
|
});
|
|
1494
1487
|
compiledInstructions.forEach(instruction => {
|
|
@@ -1781,7 +1774,7 @@ class Transaction {
|
|
|
1781
1774
|
for (let i = 0; i < signatureCount; i++) {
|
|
1782
1775
|
const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1783
1776
|
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1784
|
-
signatures.push(bs58__default
|
|
1777
|
+
signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
|
|
1785
1778
|
}
|
|
1786
1779
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
1787
1780
|
}
|
|
@@ -1797,7 +1790,7 @@ class Transaction {
|
|
|
1797
1790
|
}
|
|
1798
1791
|
signatures.forEach((signature, index) => {
|
|
1799
1792
|
const sigPubkeyPair = {
|
|
1800
|
-
signature: signature == bs58__default
|
|
1793
|
+
signature: signature == bs58__default.default.encode(DEFAULT_SIGNATURE) ? null : bs58__default.default.decode(signature),
|
|
1801
1794
|
publicKey: message.accountKeys[index]
|
|
1802
1795
|
};
|
|
1803
1796
|
transaction.signatures.push(sigPubkeyPair);
|
|
@@ -1814,7 +1807,7 @@ class Transaction {
|
|
|
1814
1807
|
transaction.instructions.push(new TransactionInstruction({
|
|
1815
1808
|
keys,
|
|
1816
1809
|
programId: message.accountKeys[instruction.programIdIndex],
|
|
1817
|
-
data: bs58__default
|
|
1810
|
+
data: bs58__default.default.decode(instruction.data)
|
|
1818
1811
|
}));
|
|
1819
1812
|
});
|
|
1820
1813
|
transaction._message = message;
|
|
@@ -3239,10 +3232,10 @@ class SolanaJSONRPCError extends Error {
|
|
|
3239
3232
|
|
|
3240
3233
|
var fetchImpl = globalThis.fetch;
|
|
3241
3234
|
|
|
3242
|
-
class RpcWebSocketClient extends RpcWebSocketCommonClient__default
|
|
3235
|
+
class RpcWebSocketClient extends RpcWebSocketCommonClient__default.default {
|
|
3243
3236
|
constructor(address, options, generate_request_id) {
|
|
3244
3237
|
const webSocketFactory = url => {
|
|
3245
|
-
const rpc = createRpc__default
|
|
3238
|
+
const rpc = createRpc__default.default(url, {
|
|
3246
3239
|
autoconnect: true,
|
|
3247
3240
|
max_reconnects: 5,
|
|
3248
3241
|
reconnect: true,
|
|
@@ -3496,7 +3489,7 @@ function versionedMessageFromResponse(version, response) {
|
|
|
3496
3489
|
compiledInstructions: response.instructions.map(ix => ({
|
|
3497
3490
|
programIdIndex: ix.programIdIndex,
|
|
3498
3491
|
accountKeyIndexes: ix.accounts,
|
|
3499
|
-
data: bs58__default
|
|
3492
|
+
data: bs58__default.default.decode(ix.data)
|
|
3500
3493
|
})),
|
|
3501
3494
|
addressTableLookups: response.addressTableLookups
|
|
3502
3495
|
});
|
|
@@ -3657,7 +3650,7 @@ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disable
|
|
|
3657
3650
|
return await fetch(...modifiedFetchArgs);
|
|
3658
3651
|
};
|
|
3659
3652
|
}
|
|
3660
|
-
const clientBrowser = new RpcClient__default
|
|
3653
|
+
const clientBrowser = new RpcClient__default.default(async (request, callback) => {
|
|
3661
3654
|
const options = {
|
|
3662
3655
|
method: 'POST',
|
|
3663
3656
|
body: request,
|
|
@@ -4976,7 +4969,7 @@ class Connection {
|
|
|
4976
4969
|
}
|
|
4977
4970
|
let decodedSignature;
|
|
4978
4971
|
try {
|
|
4979
|
-
decodedSignature = bs58__default
|
|
4972
|
+
decodedSignature = bs58__default.default.decode(rawSignature);
|
|
4980
4973
|
} catch (err) {
|
|
4981
4974
|
throw new Error('signature must be base58 encoded: ' + rawSignature);
|
|
4982
4975
|
}
|
|
@@ -6669,12 +6662,11 @@ class Connection {
|
|
|
6669
6662
|
* @internal
|
|
6670
6663
|
*/
|
|
6671
6664
|
_onSubscriptionStateChange(clientSubscriptionId, callback) {
|
|
6672
|
-
var _this$_subscriptionSt;
|
|
6673
6665
|
const hash = this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
|
|
6674
6666
|
if (hash == null) {
|
|
6675
6667
|
return () => {};
|
|
6676
6668
|
}
|
|
6677
|
-
const stateChangeCallbacks =
|
|
6669
|
+
const stateChangeCallbacks = this._subscriptionStateChangeCallbacksByHash[hash] ||= new Set();
|
|
6678
6670
|
stateChangeCallbacks.add(callback);
|
|
6679
6671
|
return () => {
|
|
6680
6672
|
stateChangeCallbacks.delete(callback);
|
|
@@ -7902,19 +7894,12 @@ class Ed25519Program {
|
|
|
7902
7894
|
}
|
|
7903
7895
|
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
7904
7896
|
|
|
7905
|
-
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
const h = hmac.hmac.create(sha256.sha256, key);
|
|
7909
|
-
msgs.forEach(msg => h.update(msg));
|
|
7910
|
-
return h.digest();
|
|
7897
|
+
const ecdsaSign = (msgHash, privKey) => {
|
|
7898
|
+
const signature = secp256k1.secp256k1.sign(msgHash, privKey);
|
|
7899
|
+
return [signature.toCompactRawBytes(), signature.recovery];
|
|
7911
7900
|
};
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
recovered: true
|
|
7915
|
-
});
|
|
7916
|
-
secp256k1__namespace.utils.isValidPrivateKey;
|
|
7917
|
-
const publicKeyCreate = secp256k1__namespace.getPublicKey;
|
|
7901
|
+
secp256k1.secp256k1.utils.isValidPrivateKey;
|
|
7902
|
+
const publicKeyCreate = secp256k1.secp256k1.getPublicKey;
|
|
7918
7903
|
|
|
7919
7904
|
const PRIVATE_KEY_BYTES = 32;
|
|
7920
7905
|
const ETHEREUM_ADDRESS_BYTES = 20;
|