@solana/web3.js 0.98.0 → 1.0.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/README.md +10 -55
- package/lib/index.browser.esm.js +48 -24
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +101 -56
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +88 -64
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +42 -25
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +27 -45
- package/src/message.ts +9 -12
- package/src/transaction.ts +2 -2
- package/src/util/guarded-array-utils.ts +37 -0
- package/src/validator-info.ts +5 -4
- package/bin/bpf-sdk-install.sh +0 -38
- package/bin/localnet.sh +0 -161
- package/bpf-sdk/LICENSE +0 -13
- package/bpf-sdk/c/README.md +0 -44
- package/bpf-sdk/c/bpf.ld +0 -20
- package/bpf-sdk/c/bpf.mk +0 -249
- package/bpf-sdk/c/inc/deserialize_deprecated.h +0 -115
- package/bpf-sdk/c/inc/solana_sdk.h +0 -669
- package/bpf-sdk/c/inc/stdio.h +0 -4
- package/bpf-sdk/c/inc/stdlib.h +0 -2
- package/bpf-sdk/c/inc/string.h +0 -7
- package/bpf-sdk/c/inc/sys/param.h +0 -1
- package/bpf-sdk/c/inc/wchar.h +0 -1
- package/bpf-sdk/env.sh +0 -39
- package/bpf-sdk/rust/bpf.ld +0 -20
- package/bpf-sdk/rust/build.sh +0 -21
- package/bpf-sdk/rust/clean.sh +0 -17
- package/bpf-sdk/rust/xargo-build.sh +0 -29
- package/bpf-sdk/scripts/dump.sh +0 -45
- package/bpf-sdk/scripts/install.sh +0 -178
- package/bpf-sdk/scripts/objcopy.sh +0 -6
- package/bpf-sdk/scripts/package.sh +0 -19
- package/bpf-sdk/scripts/strip.sh +0 -23
- package/bpf-sdk/version.txt +0 -2
- package/doc/assets/css/main.css +0 -2660
- package/doc/assets/images/icons.png +0 -0
- package/doc/assets/images/icons@2x.png +0 -0
- package/doc/assets/images/widgets.png +0 -0
- package/doc/assets/images/widgets@2x.png +0 -0
- package/doc/assets/js/main.js +0 -248
- package/doc/assets/js/search.js +0 -1
- package/doc/classes/account.html +0 -244
- package/doc/classes/authorized.html +0 -234
- package/doc/classes/bpfloader.html +0 -267
- package/doc/classes/connection.html +0 -2354
- package/doc/classes/loader.html +0 -275
- package/doc/classes/lockup.html +0 -250
- package/doc/classes/message.html +0 -326
- package/doc/classes/nonceaccount.html +0 -233
- package/doc/classes/publickey.html +0 -411
- package/doc/classes/secp256k1program.html +0 -308
- package/doc/classes/stakeinstruction.html +0 -403
- package/doc/classes/stakeprogram.html +0 -503
- package/doc/classes/systeminstruction.html +0 -563
- package/doc/classes/systemprogram.html +0 -503
- package/doc/classes/transaction.html +0 -688
- package/doc/classes/transactioninstruction.html +0 -240
- package/doc/classes/validatorinfo.html +0 -279
- package/doc/classes/voteaccount.html +0 -331
- package/doc/index.html +0 -640
- package/doc/interfaces/feecalculator.html +0 -166
- package/doc/modules.html +0 -4682
- package/examples/README.md +0 -10
- package/examples/account.html +0 -24
- package/examples/account.js +0 -10
- package/examples/bpf-c-noop/.gitignore +0 -1
- package/examples/bpf-c-noop/makefile +0 -1
- package/examples/bpf-c-noop/src/noop/noop.c +0 -19
- package/examples/bpf-rust-noop/.gitignore +0 -3
- package/examples/bpf-rust-noop/Cargo.toml +0 -23
- package/examples/bpf-rust-noop/Xargo.toml +0 -2
- package/examples/bpf-rust-noop/src/lib.rs +0 -70
- package/examples/get-balance.html +0 -37
- package/examples/get-balance.js +0 -18
package/README.md
CHANGED
|
@@ -47,11 +47,17 @@ $ npm install --save @solana/web3.js
|
|
|
47
47
|
<script src="https://unpkg.com/@solana/web3.js@0.92.0/lib/index.iife.min.js"></script>
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
## Development Environment Setup
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
Install the latest Solana release from https://docs.solana.com/cli/install-solana-cli-tools
|
|
53
|
+
|
|
54
|
+
### Run test validator
|
|
55
|
+
|
|
56
|
+
**Use `solana-test-validator` from the latest Solana release**
|
|
57
|
+
|
|
58
|
+
### BPF program development
|
|
59
|
+
|
|
60
|
+
**Use `cargo build-bpf` from the latest Solana release**
|
|
55
61
|
|
|
56
62
|
## Usage
|
|
57
63
|
|
|
@@ -84,14 +90,6 @@ activate it:
|
|
|
84
90
|
node_modules/@solana/web3.js/module.flow.js
|
|
85
91
|
```
|
|
86
92
|
|
|
87
|
-
## Examples
|
|
88
|
-
See the [examples/](https://github.com/solana-labs/solana-web3.js/tree/master/examples) directory for small snippets.
|
|
89
|
-
|
|
90
|
-
Standalone examples:
|
|
91
|
-
* Message feed (BPF Rust and C): https://github.com/solana-labs/example-messagefeed
|
|
92
|
-
* Tic-tac-toe (BPF C): https://github.com/solana-labs/example-tictactoe
|
|
93
|
-
* Web wallet: https://github.com/solana-labs/example-webwallet
|
|
94
|
-
|
|
95
93
|
## Releases
|
|
96
94
|
Releases are available on [Github](https://github.com/solana-labs/solana-web3.js/releases)
|
|
97
95
|
and [npmjs.com](https://www.npmjs.com/package/@solana/web3.js)
|
|
@@ -99,46 +97,3 @@ and [npmjs.com](https://www.npmjs.com/package/@solana/web3.js)
|
|
|
99
97
|
Each Github release features a tarball containing API documentation and a
|
|
100
98
|
minified version of the module suitable for direct use in a browser environment
|
|
101
99
|
(<script> tag)
|
|
102
|
-
|
|
103
|
-
## Deprecated
|
|
104
|
-
|
|
105
|
-
### Local Network
|
|
106
|
-
|
|
107
|
-
**Please use `solana-test-validator` from the latest Solana release instead of the information in this section**
|
|
108
|
-
|
|
109
|
-
The `solana-localnet` program is provided to easily start a test Solana cluster
|
|
110
|
-
locally on your machine. Docker must be installed. The JSON RPC endpoint of
|
|
111
|
-
the local cluster is `http://localhost:8899`.
|
|
112
|
-
|
|
113
|
-
To start, first fetch the latest Docker image by running:
|
|
114
|
-
```bash
|
|
115
|
-
$ npx solana-localnet update
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
Then run the following command to start the cluster
|
|
119
|
-
```bash
|
|
120
|
-
$ npx solana-localnet up
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
While the cluster is running logs are available with:
|
|
124
|
-
```bash
|
|
125
|
-
$ npx solana-localnet logs -f
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
Stop the cluster with:
|
|
129
|
-
```bash
|
|
130
|
-
$ npx solana-localnet down
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### BPF program development
|
|
134
|
-
|
|
135
|
-
**Please use `cargo build-bpf` from the latest Solana release instead of the information in this section**
|
|
136
|
-
|
|
137
|
-
The Solana BPF SDK is located in the `bpf-sdk/` subdirectory if you installed
|
|
138
|
-
solana-web3.js from npmjs.com.
|
|
139
|
-
|
|
140
|
-
From a git clone, run `npm run bpf-sdk:install` to fetch the latest BPF SDK.
|
|
141
|
-
|
|
142
|
-
Additionally Rust must be installed to build Rust BPF programs such as
|
|
143
|
-
`examples/bpf-rust-noop/`. See https://www.rust-lang.org/install.html for
|
|
144
|
-
installation details.
|
package/lib/index.browser.esm.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import
|
|
2
|
+
import * as nacl from 'tweetnacl';
|
|
3
|
+
import nacl__default from 'tweetnacl';
|
|
3
4
|
import BN from 'bn.js';
|
|
4
5
|
import { sha256 } from 'crypto-hash';
|
|
5
6
|
import fetch from 'node-fetch';
|
|
@@ -2696,7 +2697,7 @@ class PublicKey {
|
|
|
2696
2697
|
|
|
2697
2698
|
} // @ts-ignore
|
|
2698
2699
|
|
|
2699
|
-
let naclLowLevel =
|
|
2700
|
+
let naclLowLevel = nacl__default.lowlevel; // Check that a pubkey is on the curve.
|
|
2700
2701
|
// This function and its dependents were sourced from:
|
|
2701
2702
|
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
2702
2703
|
|
|
@@ -2764,9 +2765,9 @@ class Account {
|
|
|
2764
2765
|
_defineProperty(this, "_keypair", void 0);
|
|
2765
2766
|
|
|
2766
2767
|
if (secretKey) {
|
|
2767
|
-
this._keypair = sign.keyPair.fromSecretKey(toBuffer(secretKey));
|
|
2768
|
+
this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
|
|
2768
2769
|
} else {
|
|
2769
|
-
this._keypair = sign.keyPair();
|
|
2770
|
+
this._keypair = nacl.sign.keyPair();
|
|
2770
2771
|
}
|
|
2771
2772
|
}
|
|
2772
2773
|
/**
|
|
@@ -4728,6 +4729,36 @@ function encodeLength(bytes, len) {
|
|
|
4728
4729
|
}
|
|
4729
4730
|
}
|
|
4730
4731
|
|
|
4732
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
4733
|
+
/**
|
|
4734
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
4735
|
+
*/
|
|
4736
|
+
|
|
4737
|
+
function guardedShift(byteArray) {
|
|
4738
|
+
if (byteArray.length === 0) {
|
|
4739
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
4740
|
+
}
|
|
4741
|
+
|
|
4742
|
+
return byteArray.shift();
|
|
4743
|
+
}
|
|
4744
|
+
/**
|
|
4745
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
4746
|
+
* the array.
|
|
4747
|
+
*/
|
|
4748
|
+
|
|
4749
|
+
function guardedSplice(byteArray, ...args) {
|
|
4750
|
+
var _args$;
|
|
4751
|
+
|
|
4752
|
+
const [start] = args;
|
|
4753
|
+
|
|
4754
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
4755
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
4756
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
4757
|
+
}
|
|
4758
|
+
|
|
4759
|
+
return byteArray.splice(...args);
|
|
4760
|
+
}
|
|
4761
|
+
|
|
4731
4762
|
/**
|
|
4732
4763
|
* The message header, identifying signed and read-only account
|
|
4733
4764
|
*
|
|
@@ -4818,32 +4849,28 @@ class Message {
|
|
|
4818
4849
|
static from(buffer$1) {
|
|
4819
4850
|
// Slice up wire data
|
|
4820
4851
|
let byteArray = [...buffer$1];
|
|
4821
|
-
const numRequiredSignatures = byteArray
|
|
4822
|
-
const numReadonlySignedAccounts = byteArray
|
|
4823
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
4852
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
4853
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
4854
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
4824
4855
|
const accountCount = decodeLength(byteArray);
|
|
4825
4856
|
let accountKeys = [];
|
|
4826
4857
|
|
|
4827
4858
|
for (let i = 0; i < accountCount; i++) {
|
|
4828
|
-
const account = byteArray
|
|
4829
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
4859
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
4830
4860
|
accountKeys.push(bs58.encode(buffer.Buffer.from(account)));
|
|
4831
4861
|
}
|
|
4832
4862
|
|
|
4833
|
-
const recentBlockhash = byteArray
|
|
4834
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
4863
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
4835
4864
|
const instructionCount = decodeLength(byteArray);
|
|
4836
4865
|
let instructions = [];
|
|
4837
4866
|
|
|
4838
4867
|
for (let i = 0; i < instructionCount; i++) {
|
|
4839
|
-
const programIdIndex = byteArray
|
|
4868
|
+
const programIdIndex = guardedShift(byteArray);
|
|
4840
4869
|
const accountCount = decodeLength(byteArray);
|
|
4841
|
-
const accounts = byteArray
|
|
4842
|
-
byteArray = byteArray.slice(accountCount);
|
|
4870
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
4843
4871
|
const dataLength = decodeLength(byteArray);
|
|
4844
|
-
const dataSlice = byteArray
|
|
4872
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
4845
4873
|
const data = bs58.encode(buffer.Buffer.from(dataSlice));
|
|
4846
|
-
byteArray = byteArray.slice(dataLength);
|
|
4847
4874
|
instructions.push({
|
|
4848
4875
|
programIdIndex,
|
|
4849
4876
|
accounts,
|
|
@@ -5314,7 +5341,7 @@ class Transaction {
|
|
|
5314
5341
|
_partialSign(message, ...signers) {
|
|
5315
5342
|
const signData = message.serialize();
|
|
5316
5343
|
signers.forEach(signer => {
|
|
5317
|
-
const signature =
|
|
5344
|
+
const signature = nacl__default.sign.detached(signData, signer.secretKey);
|
|
5318
5345
|
|
|
5319
5346
|
this._addSignature(signer.publicKey, toBuffer(signature));
|
|
5320
5347
|
});
|
|
@@ -5370,7 +5397,7 @@ class Transaction {
|
|
|
5370
5397
|
return false;
|
|
5371
5398
|
}
|
|
5372
5399
|
} else {
|
|
5373
|
-
if (!
|
|
5400
|
+
if (!nacl__default.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
|
|
5374
5401
|
return false;
|
|
5375
5402
|
}
|
|
5376
5403
|
}
|
|
@@ -5468,8 +5495,7 @@ class Transaction {
|
|
|
5468
5495
|
let signatures = [];
|
|
5469
5496
|
|
|
5470
5497
|
for (let i = 0; i < signatureCount; i++) {
|
|
5471
|
-
const signature = byteArray
|
|
5472
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
5498
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
5473
5499
|
signatures.push(bs58.encode(buffer.Buffer.from(signature)));
|
|
5474
5500
|
}
|
|
5475
5501
|
|
|
@@ -11106,10 +11132,8 @@ class ValidatorInfo {
|
|
|
11106
11132
|
const configKeys = [];
|
|
11107
11133
|
|
|
11108
11134
|
for (let i = 0; i < 2; i++) {
|
|
11109
|
-
const publicKey = new PublicKey(byteArray
|
|
11110
|
-
|
|
11111
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
11112
|
-
byteArray = byteArray.slice(1);
|
|
11135
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
11136
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
11113
11137
|
configKeys.push({
|
|
11114
11138
|
publicKey,
|
|
11115
11139
|
isSigner
|