@solana/web3.js 1.54.0 → 1.54.2
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 +180 -1830
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +180 -1830
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +180 -1851
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +15 -6
- package/lib/index.esm.js +180 -1851
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +19258 -26041
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +8 -5
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +180 -1830
- package/lib/index.native.js.map +1 -1
- package/package.json +26 -27
- package/src/account.ts +18 -9
- package/src/keypair.ts +19 -24
- package/src/message/legacy.ts +9 -12
- package/src/message/v0.ts +29 -12
- package/src/programs/ed25519.ts +2 -2
- package/src/programs/secp256k1.ts +6 -5
- package/src/publickey.ts +7 -71
- package/src/transaction/legacy.ts +5 -7
- package/src/transaction/versioned.ts +4 -6
- package/src/utils/ed25519.ts +46 -0
- package/src/utils/guarded-array-utils.ts +34 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/secp256k1.ts +18 -0
- package/src/validator-info.ts +5 -4
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
5
|
+
*/
|
|
6
|
+
export function guardedShift<T>(byteArray: T[]): T {
|
|
7
|
+
if (byteArray.length === 0) {
|
|
8
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
9
|
+
}
|
|
10
|
+
return byteArray.shift() as T;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
15
|
+
* the array.
|
|
16
|
+
*/
|
|
17
|
+
export function guardedSplice<T>(
|
|
18
|
+
byteArray: T[],
|
|
19
|
+
...args:
|
|
20
|
+
| [start: number, deleteCount?: number]
|
|
21
|
+
| [start: number, deleteCount: number, ...items: T[]]
|
|
22
|
+
): T[] {
|
|
23
|
+
const [start] = args;
|
|
24
|
+
if (
|
|
25
|
+
args.length === 2 // Implies that `deleteCount` was supplied
|
|
26
|
+
? start + (args[1] ?? 0) > byteArray.length
|
|
27
|
+
: start >= byteArray.length
|
|
28
|
+
) {
|
|
29
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
30
|
+
}
|
|
31
|
+
return byteArray.splice(
|
|
32
|
+
...(args as Parameters<typeof Array.prototype.splice>),
|
|
33
|
+
);
|
|
34
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {hmac} from '@noble/hashes/hmac';
|
|
2
|
+
import {sha256} from '@noble/hashes/sha256';
|
|
3
|
+
import * as secp256k1 from '@noble/secp256k1';
|
|
4
|
+
|
|
5
|
+
// Supply a synchronous hashing algorithm to make this
|
|
6
|
+
// library interoperable with the synchronous APIs in web3.js.
|
|
7
|
+
secp256k1.utils.hmacSha256Sync = (key: Uint8Array, ...msgs: Uint8Array[]) => {
|
|
8
|
+
const h = hmac.create(sha256, key);
|
|
9
|
+
msgs.forEach(msg => h.update(msg));
|
|
10
|
+
return h.digest();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const ecdsaSign = (
|
|
14
|
+
msgHash: Parameters<typeof secp256k1.signSync>[0],
|
|
15
|
+
privKey: Parameters<typeof secp256k1.signSync>[1],
|
|
16
|
+
) => secp256k1.signSync(msgHash, privKey, {der: false, recovered: true});
|
|
17
|
+
export const isValidPrivateKey = secp256k1.utils.isValidPrivateKey;
|
|
18
|
+
export const publicKeyCreate = secp256k1.getPublicKey;
|
package/src/validator-info.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import * as Layout from './layout';
|
|
10
10
|
import * as shortvec from './utils/shortvec-encoding';
|
|
11
11
|
import {PublicKey, PUBLIC_KEY_LENGTH} from './publickey';
|
|
12
|
+
import {guardedShift, guardedSplice} from './utils/guarded-array-utils';
|
|
12
13
|
|
|
13
14
|
export const VALIDATOR_INFO_KEY = new PublicKey(
|
|
14
15
|
'Va1idator1nfo111111111111111111111111111111',
|
|
@@ -83,10 +84,10 @@ export class ValidatorInfo {
|
|
|
83
84
|
|
|
84
85
|
const configKeys: Array<ConfigKey> = [];
|
|
85
86
|
for (let i = 0; i < 2; i++) {
|
|
86
|
-
const publicKey = new PublicKey(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
const publicKey = new PublicKey(
|
|
88
|
+
guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH),
|
|
89
|
+
);
|
|
90
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
90
91
|
configKeys.push({publicKey, isSigner});
|
|
91
92
|
}
|
|
92
93
|
|