@solana/web3.js 1.75.1 → 1.76.1
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 +45 -59
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +10 -20
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +59 -73
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +10 -20
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +3104 -1750
- 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 +45 -59
- 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.native.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();
|
|
@@ -759,7 +752,7 @@ class Message {
|
|
|
759
752
|
return this.instructions.map(ix => ({
|
|
760
753
|
programIdIndex: ix.programIdIndex,
|
|
761
754
|
accountKeyIndexes: ix.accounts,
|
|
762
|
-
data: bs58__default
|
|
755
|
+
data: bs58__default.default.decode(ix.data)
|
|
763
756
|
}));
|
|
764
757
|
}
|
|
765
758
|
get addressTableLookups() {
|
|
@@ -775,7 +768,7 @@ class Message {
|
|
|
775
768
|
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
776
769
|
programIdIndex: ix.programIdIndex,
|
|
777
770
|
accounts: ix.accountKeyIndexes,
|
|
778
|
-
data: bs58__default
|
|
771
|
+
data: bs58__default.default.encode(ix.data)
|
|
779
772
|
}));
|
|
780
773
|
return new Message({
|
|
781
774
|
header,
|
|
@@ -817,7 +810,7 @@ class Message {
|
|
|
817
810
|
accounts,
|
|
818
811
|
programIdIndex
|
|
819
812
|
} = instruction;
|
|
820
|
-
const data = Array.from(bs58__default
|
|
813
|
+
const data = Array.from(bs58__default.default.decode(instruction.data));
|
|
821
814
|
let keyIndicesCount = [];
|
|
822
815
|
encodeLength(keyIndicesCount, accounts.length);
|
|
823
816
|
let dataCount = [];
|
|
@@ -848,7 +841,7 @@ class Message {
|
|
|
848
841
|
numReadonlyUnsignedAccounts: buffer.Buffer.from([this.header.numReadonlyUnsignedAccounts]),
|
|
849
842
|
keyCount: buffer.Buffer.from(keyCount),
|
|
850
843
|
keys: this.accountKeys.map(key => toBuffer(key.toBytes())),
|
|
851
|
-
recentBlockhash: bs58__default
|
|
844
|
+
recentBlockhash: bs58__default.default.decode(this.recentBlockhash)
|
|
852
845
|
};
|
|
853
846
|
let signData = buffer.Buffer.alloc(2048);
|
|
854
847
|
const length = signDataLayout.encode(transaction, signData);
|
|
@@ -883,7 +876,7 @@ class Message {
|
|
|
883
876
|
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
884
877
|
const dataLength = decodeLength(byteArray);
|
|
885
878
|
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
886
|
-
const data = bs58__default
|
|
879
|
+
const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
|
|
887
880
|
instructions.push({
|
|
888
881
|
programIdIndex,
|
|
889
882
|
accounts,
|
|
@@ -896,7 +889,7 @@ class Message {
|
|
|
896
889
|
numReadonlySignedAccounts,
|
|
897
890
|
numReadonlyUnsignedAccounts
|
|
898
891
|
},
|
|
899
|
-
recentBlockhash: bs58__default
|
|
892
|
+
recentBlockhash: bs58__default.default.encode(buffer.Buffer.from(recentBlockhash)),
|
|
900
893
|
accountKeys,
|
|
901
894
|
instructions
|
|
902
895
|
};
|
|
@@ -1040,7 +1033,7 @@ class MessageV0 {
|
|
|
1040
1033
|
header: this.header,
|
|
1041
1034
|
staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
|
|
1042
1035
|
staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
|
|
1043
|
-
recentBlockhash: bs58__default
|
|
1036
|
+
recentBlockhash: bs58__default.default.decode(this.recentBlockhash),
|
|
1044
1037
|
instructionsLength: new Uint8Array(encodedInstructionsLength),
|
|
1045
1038
|
serializedInstructions,
|
|
1046
1039
|
addressTableLookupsLength: new Uint8Array(encodedAddressTableLookupsLength),
|
|
@@ -1103,7 +1096,7 @@ class MessageV0 {
|
|
|
1103
1096
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1104
1097
|
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1105
1098
|
}
|
|
1106
|
-
const recentBlockhash = bs58__default
|
|
1099
|
+
const recentBlockhash = bs58__default.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1107
1100
|
const instructionCount = decodeLength(byteArray);
|
|
1108
1101
|
const compiledInstructions = [];
|
|
1109
1102
|
for (let i = 0; i < instructionCount; i++) {
|
|
@@ -1509,7 +1502,7 @@ class Transaction {
|
|
|
1509
1502
|
return {
|
|
1510
1503
|
programIdIndex: accountKeys.indexOf(programId.toString()),
|
|
1511
1504
|
accounts: instruction.keys.map(meta => accountKeys.indexOf(meta.pubkey.toString())),
|
|
1512
|
-
data: bs58__default
|
|
1505
|
+
data: bs58__default.default.encode(data)
|
|
1513
1506
|
};
|
|
1514
1507
|
});
|
|
1515
1508
|
compiledInstructions.forEach(instruction => {
|
|
@@ -1801,7 +1794,7 @@ class Transaction {
|
|
|
1801
1794
|
let signatures = [];
|
|
1802
1795
|
for (let i = 0; i < signatureCount; i++) {
|
|
1803
1796
|
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1804
|
-
signatures.push(bs58__default
|
|
1797
|
+
signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
|
|
1805
1798
|
}
|
|
1806
1799
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
1807
1800
|
}
|
|
@@ -1817,7 +1810,7 @@ class Transaction {
|
|
|
1817
1810
|
}
|
|
1818
1811
|
signatures.forEach((signature, index) => {
|
|
1819
1812
|
const sigPubkeyPair = {
|
|
1820
|
-
signature: signature == bs58__default
|
|
1813
|
+
signature: signature == bs58__default.default.encode(DEFAULT_SIGNATURE) ? null : bs58__default.default.decode(signature),
|
|
1821
1814
|
publicKey: message.accountKeys[index]
|
|
1822
1815
|
};
|
|
1823
1816
|
transaction.signatures.push(sigPubkeyPair);
|
|
@@ -1834,7 +1827,7 @@ class Transaction {
|
|
|
1834
1827
|
transaction.instructions.push(new TransactionInstruction({
|
|
1835
1828
|
keys,
|
|
1836
1829
|
programId: message.accountKeys[instruction.programIdIndex],
|
|
1837
|
-
data: bs58__default
|
|
1830
|
+
data: bs58__default.default.decode(instruction.data)
|
|
1838
1831
|
}));
|
|
1839
1832
|
});
|
|
1840
1833
|
transaction._message = message;
|
|
@@ -3259,10 +3252,10 @@ class SolanaJSONRPCError extends Error {
|
|
|
3259
3252
|
|
|
3260
3253
|
var fetchImpl = globalThis.fetch;
|
|
3261
3254
|
|
|
3262
|
-
class RpcWebSocketClient extends RpcWebSocketCommonClient__default
|
|
3255
|
+
class RpcWebSocketClient extends RpcWebSocketCommonClient__default.default {
|
|
3263
3256
|
constructor(address, options, generate_request_id) {
|
|
3264
3257
|
const webSocketFactory = url => {
|
|
3265
|
-
const rpc = createRpc__default
|
|
3258
|
+
const rpc = createRpc__default.default(url, {
|
|
3266
3259
|
autoconnect: true,
|
|
3267
3260
|
max_reconnects: 5,
|
|
3268
3261
|
reconnect: true,
|
|
@@ -3516,7 +3509,7 @@ function versionedMessageFromResponse(version, response) {
|
|
|
3516
3509
|
compiledInstructions: response.instructions.map(ix => ({
|
|
3517
3510
|
programIdIndex: ix.programIdIndex,
|
|
3518
3511
|
accountKeyIndexes: ix.accounts,
|
|
3519
|
-
data: bs58__default
|
|
3512
|
+
data: bs58__default.default.decode(ix.data)
|
|
3520
3513
|
})),
|
|
3521
3514
|
addressTableLookups: response.addressTableLookups
|
|
3522
3515
|
});
|
|
@@ -3677,7 +3670,7 @@ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disable
|
|
|
3677
3670
|
return await fetch(...modifiedFetchArgs);
|
|
3678
3671
|
};
|
|
3679
3672
|
}
|
|
3680
|
-
const clientBrowser = new RpcClient__default
|
|
3673
|
+
const clientBrowser = new RpcClient__default.default(async (request, callback) => {
|
|
3681
3674
|
const options = {
|
|
3682
3675
|
method: 'POST',
|
|
3683
3676
|
body: request,
|
|
@@ -4460,7 +4453,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4460
4453
|
|
|
4461
4454
|
/** @internal */
|
|
4462
4455
|
const COMMON_HTTP_HEADERS = {
|
|
4463
|
-
'solana-client': `js/${"1.
|
|
4456
|
+
'solana-client': `js/${"1.76.1" }`
|
|
4464
4457
|
};
|
|
4465
4458
|
|
|
4466
4459
|
/**
|
|
@@ -4996,7 +4989,7 @@ class Connection {
|
|
|
4996
4989
|
}
|
|
4997
4990
|
let decodedSignature;
|
|
4998
4991
|
try {
|
|
4999
|
-
decodedSignature = bs58__default
|
|
4992
|
+
decodedSignature = bs58__default.default.decode(rawSignature);
|
|
5000
4993
|
} catch (err) {
|
|
5001
4994
|
throw new Error('signature must be base58 encoded: ' + rawSignature);
|
|
5002
4995
|
}
|
|
@@ -7921,19 +7914,12 @@ class Ed25519Program {
|
|
|
7921
7914
|
}
|
|
7922
7915
|
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
7923
7916
|
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
|
|
7927
|
-
const h = hmac.hmac.create(sha256.sha256, key);
|
|
7928
|
-
msgs.forEach(msg => h.update(msg));
|
|
7929
|
-
return h.digest();
|
|
7917
|
+
const ecdsaSign = (msgHash, privKey) => {
|
|
7918
|
+
const signature = secp256k1.secp256k1.sign(msgHash, privKey);
|
|
7919
|
+
return [signature.toCompactRawBytes(), signature.recovery];
|
|
7930
7920
|
};
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
recovered: true
|
|
7934
|
-
});
|
|
7935
|
-
secp256k1__namespace.utils.isValidPrivateKey;
|
|
7936
|
-
const publicKeyCreate = secp256k1__namespace.getPublicKey;
|
|
7921
|
+
secp256k1.secp256k1.utils.isValidPrivateKey;
|
|
7922
|
+
const publicKeyCreate = secp256k1.secp256k1.getPublicKey;
|
|
7937
7923
|
|
|
7938
7924
|
const PRIVATE_KEY_BYTES = 32;
|
|
7939
7925
|
const ETHEREUM_ADDRESS_BYTES = 20;
|