@solana/web3.js 0.0.0-next
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/LICENSE +20 -0
- package/README.md +158 -0
- package/lib/index.browser.cjs.js +10062 -0
- package/lib/index.browser.cjs.js.map +1 -0
- package/lib/index.browser.esm.js +9976 -0
- package/lib/index.browser.esm.js.map +1 -0
- package/lib/index.cjs.js +9568 -0
- package/lib/index.cjs.js.map +1 -0
- package/lib/index.d.ts +3311 -0
- package/lib/index.esm.js +9479 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.iife.js +30136 -0
- package/lib/index.iife.js.map +1 -0
- package/lib/index.iife.min.js +40 -0
- package/lib/index.iife.min.js.map +1 -0
- package/package.json +140 -0
- package/src/account.ts +46 -0
- package/src/agent-manager.ts +44 -0
- package/src/blockhash.ts +4 -0
- package/src/bpf-loader-deprecated.ts +5 -0
- package/src/bpf-loader.ts +45 -0
- package/src/connection.ts +4935 -0
- package/src/ed25519-program.ts +157 -0
- package/src/epoch-schedule.ts +102 -0
- package/src/errors.ts +9 -0
- package/src/fee-calculator.ts +16 -0
- package/src/index.ts +31 -0
- package/src/instruction.ts +58 -0
- package/src/keypair.ts +98 -0
- package/src/layout.ts +147 -0
- package/src/loader.ts +236 -0
- package/src/message.ts +271 -0
- package/src/nonce-account.ts +78 -0
- package/src/publickey.ts +296 -0
- package/src/secp256k1-program.ts +229 -0
- package/src/stake-program.ts +923 -0
- package/src/system-program.ts +1007 -0
- package/src/sysvar.ts +37 -0
- package/src/timing.ts +23 -0
- package/src/transaction.ts +808 -0
- package/src/util/assert.ts +8 -0
- package/src/util/borsh-schema.ts +38 -0
- package/src/util/cluster.ts +31 -0
- package/src/util/promise-timeout.ts +14 -0
- package/src/util/send-and-confirm-raw-transaction.ts +46 -0
- package/src/util/send-and-confirm-transaction.ts +50 -0
- package/src/util/shortvec-encoding.ts +28 -0
- package/src/util/sleep.ts +4 -0
- package/src/util/to-buffer.ts +11 -0
- package/src/util/url.ts +18 -0
- package/src/validator-info.ts +106 -0
- package/src/vote-account.ts +236 -0
- package/src/vote-program.ts +413 -0
package/package.json
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solana/web3.js",
|
|
3
|
+
"version": "0.0.0-next",
|
|
4
|
+
"description": "Solana Javascript API",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"api",
|
|
7
|
+
"blockchain"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Solana Maintainers <maintainers@solana.com>",
|
|
11
|
+
"homepage": "https://solana.com/",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/solana-labs/solana-web3.js.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "http://github.com/solana-labs/solana-web3.js.git/issues"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"browser": {
|
|
23
|
+
"./lib/index.cjs.js": "./lib/index.browser.cjs.js",
|
|
24
|
+
"./lib/index.esm.js": "./lib/index.browser.esm.js"
|
|
25
|
+
},
|
|
26
|
+
"main": "lib/index.cjs.js",
|
|
27
|
+
"module": "lib/index.esm.js",
|
|
28
|
+
"types": "lib/index.d.ts",
|
|
29
|
+
"browserslist": [
|
|
30
|
+
"defaults",
|
|
31
|
+
"not IE 11",
|
|
32
|
+
"maintained node versions"
|
|
33
|
+
],
|
|
34
|
+
"files": [
|
|
35
|
+
"/lib",
|
|
36
|
+
"/src"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen",
|
|
40
|
+
"build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
|
|
41
|
+
"clean": "rimraf ./coverage ./lib",
|
|
42
|
+
"codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
|
|
43
|
+
"dev": "cross-env NODE_ENV=development rollup -c",
|
|
44
|
+
"doc": "set -ex; typedoc --treatWarningsAsErrors",
|
|
45
|
+
"type:gen": "./scripts/typegen.sh",
|
|
46
|
+
"lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
|
|
47
|
+
"lint:fix": "npm run pretty:fix && eslint . --fix --ext .js,.ts",
|
|
48
|
+
"type:check": "tsc -p tsconfig.json --noEmit",
|
|
49
|
+
"ok": "run-s lint test doc type:check",
|
|
50
|
+
"pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
|
|
51
|
+
"pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
|
|
52
|
+
"re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
|
|
53
|
+
"test": "mocha -r ts-node/register './test/**/*.test.ts'",
|
|
54
|
+
"test:cover": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=lcov mocha -r ts-node/register './test/**/*.test.ts'",
|
|
55
|
+
"test:live": "TEST_LIVE=1 npm run test",
|
|
56
|
+
"test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@babel/runtime": "^7.12.5",
|
|
60
|
+
"@ethersproject/sha2": "^5.5.0",
|
|
61
|
+
"@solana/buffer-layout": "^4.0.0",
|
|
62
|
+
"bn.js": "^5.0.0",
|
|
63
|
+
"borsh": "^0.7.0",
|
|
64
|
+
"bs58": "^4.0.1",
|
|
65
|
+
"buffer": "6.0.1",
|
|
66
|
+
"cross-fetch": "^3.1.4",
|
|
67
|
+
"fast-stable-stringify": "^1.0.0",
|
|
68
|
+
"jayson": "^3.4.4",
|
|
69
|
+
"js-sha3": "^0.8.0",
|
|
70
|
+
"rpc-websockets": "^7.4.2",
|
|
71
|
+
"secp256k1": "^4.0.2",
|
|
72
|
+
"sinon-chai": "^3.7.0",
|
|
73
|
+
"superstruct": "^0.14.2",
|
|
74
|
+
"tweetnacl": "^1.0.0"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@babel/core": "^7.12.13",
|
|
78
|
+
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
|
79
|
+
"@babel/plugin-transform-runtime": "^7.12.10",
|
|
80
|
+
"@babel/preset-env": "^7.12.11",
|
|
81
|
+
"@babel/preset-typescript": "^7.12.16",
|
|
82
|
+
"@babel/register": "^7.12.13",
|
|
83
|
+
"@commitlint/config-conventional": "^15.0.0",
|
|
84
|
+
"@commitlint/travis-cli": "^16.2.3",
|
|
85
|
+
"@rollup/plugin-alias": "^3.1.2",
|
|
86
|
+
"@rollup/plugin-babel": "^5.2.3",
|
|
87
|
+
"@rollup/plugin-commonjs": "^21.0.0",
|
|
88
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
89
|
+
"@rollup/plugin-multi-entry": "^4.0.0",
|
|
90
|
+
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
91
|
+
"@rollup/plugin-replace": "^3.0.0",
|
|
92
|
+
"@solana/spl-token": "^0.1.2",
|
|
93
|
+
"@types/bn.js": "^5.1.0",
|
|
94
|
+
"@types/bs58": "^4.0.1",
|
|
95
|
+
"@types/chai": "^4.2.15",
|
|
96
|
+
"@types/chai-as-promised": "^7.1.3",
|
|
97
|
+
"@types/express-serve-static-core": "^4.17.21",
|
|
98
|
+
"@types/mocha": "^9.0.0",
|
|
99
|
+
"@types/mz": "^2.7.3",
|
|
100
|
+
"@types/node": "^17.0.24",
|
|
101
|
+
"@types/secp256k1": "^4.0.1",
|
|
102
|
+
"@types/sinon": "^10.0.0",
|
|
103
|
+
"@types/sinon-chai": "^3.2.8",
|
|
104
|
+
"@typescript-eslint/eslint-plugin": "^4.14.2",
|
|
105
|
+
"@typescript-eslint/parser": "^4.14.2",
|
|
106
|
+
"chai": "^4.3.0",
|
|
107
|
+
"chai-as-promised": "^7.1.1",
|
|
108
|
+
"codecov": "^3.0.4",
|
|
109
|
+
"cross-env": "7.0.3",
|
|
110
|
+
"eslint": "^7.19.0",
|
|
111
|
+
"eslint-config-prettier": "^8.0.0",
|
|
112
|
+
"eslint-plugin-import": "2.25.3",
|
|
113
|
+
"eslint-plugin-mocha": "^9.0.0",
|
|
114
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
115
|
+
"esm": "^3.2.25",
|
|
116
|
+
"http-server": "^14.0.0",
|
|
117
|
+
"mocha": "^8.2.1",
|
|
118
|
+
"mockttp": "^2.0.1",
|
|
119
|
+
"mz": "^2.7.0",
|
|
120
|
+
"npm-run-all": "^4.1.5",
|
|
121
|
+
"nyc": "^15.1.0",
|
|
122
|
+
"prettier": "^2.3.0",
|
|
123
|
+
"puppeteer": "^12.0.0",
|
|
124
|
+
"rimraf": "3.0.2",
|
|
125
|
+
"rollup": "2.60.2",
|
|
126
|
+
"rollup-plugin-dts": "^4.0.0",
|
|
127
|
+
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
128
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
129
|
+
"semantic-release": "^18.0.0",
|
|
130
|
+
"sinon": "^12.0.0",
|
|
131
|
+
"start-server-and-test": "^1.12.0",
|
|
132
|
+
"ts-node": "^10.0.0",
|
|
133
|
+
"tslib": "^2.1.0",
|
|
134
|
+
"typedoc": "^0.22.2",
|
|
135
|
+
"typescript": "^4.3.2"
|
|
136
|
+
},
|
|
137
|
+
"engines": {
|
|
138
|
+
"node": ">=12.20.0"
|
|
139
|
+
}
|
|
140
|
+
}
|
package/src/account.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import nacl from 'tweetnacl';
|
|
2
|
+
import type {SignKeyPair as KeyPair} from 'tweetnacl';
|
|
3
|
+
import type {Buffer} from 'buffer';
|
|
4
|
+
|
|
5
|
+
import {toBuffer} from './util/to-buffer';
|
|
6
|
+
import {PublicKey} from './publickey';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An account key pair (public and secret keys).
|
|
10
|
+
*
|
|
11
|
+
* @deprecated since v1.10.0, please use {@link Keypair} instead.
|
|
12
|
+
*/
|
|
13
|
+
export class Account {
|
|
14
|
+
/** @internal */
|
|
15
|
+
_keypair: KeyPair;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create a new Account object
|
|
19
|
+
*
|
|
20
|
+
* If the secretKey parameter is not provided a new key pair is randomly
|
|
21
|
+
* created for the account
|
|
22
|
+
*
|
|
23
|
+
* @param secretKey Secret key for the account
|
|
24
|
+
*/
|
|
25
|
+
constructor(secretKey?: Buffer | Uint8Array | Array<number>) {
|
|
26
|
+
if (secretKey) {
|
|
27
|
+
this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
|
|
28
|
+
} else {
|
|
29
|
+
this._keypair = nacl.sign.keyPair();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The public key for this account
|
|
35
|
+
*/
|
|
36
|
+
get publicKey(): PublicKey {
|
|
37
|
+
return new PublicKey(this._keypair.publicKey);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The **unencrypted** secret key for this account
|
|
42
|
+
*/
|
|
43
|
+
get secretKey(): Buffer {
|
|
44
|
+
return toBuffer(this._keypair.secretKey);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import https from 'https';
|
|
3
|
+
|
|
4
|
+
export const DESTROY_TIMEOUT_MS = 5000;
|
|
5
|
+
|
|
6
|
+
export class AgentManager {
|
|
7
|
+
_agent: http.Agent | https.Agent;
|
|
8
|
+
_activeRequests = 0;
|
|
9
|
+
_destroyTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
10
|
+
_useHttps: boolean;
|
|
11
|
+
|
|
12
|
+
static _newAgent(useHttps: boolean): http.Agent | https.Agent {
|
|
13
|
+
const options = {keepAlive: true, maxSockets: 25};
|
|
14
|
+
if (useHttps) {
|
|
15
|
+
return new https.Agent(options);
|
|
16
|
+
} else {
|
|
17
|
+
return new http.Agent(options);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(useHttps?: boolean) {
|
|
22
|
+
this._useHttps = useHttps === true;
|
|
23
|
+
this._agent = AgentManager._newAgent(this._useHttps);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
requestStart(): http.Agent | https.Agent {
|
|
27
|
+
this._activeRequests++;
|
|
28
|
+
if (this._destroyTimeout !== null) {
|
|
29
|
+
clearTimeout(this._destroyTimeout);
|
|
30
|
+
this._destroyTimeout = null;
|
|
31
|
+
}
|
|
32
|
+
return this._agent;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
requestEnd() {
|
|
36
|
+
this._activeRequests--;
|
|
37
|
+
if (this._activeRequests === 0 && this._destroyTimeout === null) {
|
|
38
|
+
this._destroyTimeout = setTimeout(() => {
|
|
39
|
+
this._agent.destroy();
|
|
40
|
+
this._agent = AgentManager._newAgent(this._useHttps);
|
|
41
|
+
}, DESTROY_TIMEOUT_MS);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/blockhash.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type {Buffer} from 'buffer';
|
|
2
|
+
|
|
3
|
+
import {PublicKey} from './publickey';
|
|
4
|
+
import {Loader} from './loader';
|
|
5
|
+
import type {Connection} from './connection';
|
|
6
|
+
import type {Signer} from './keypair';
|
|
7
|
+
|
|
8
|
+
export const BPF_LOADER_PROGRAM_ID = new PublicKey(
|
|
9
|
+
'BPFLoader2111111111111111111111111111111111',
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Factory class for transactions to interact with a program loader
|
|
14
|
+
*/
|
|
15
|
+
export class BpfLoader {
|
|
16
|
+
/**
|
|
17
|
+
* Minimum number of signatures required to load a program not including
|
|
18
|
+
* retries
|
|
19
|
+
*
|
|
20
|
+
* Can be used to calculate transaction fees
|
|
21
|
+
*/
|
|
22
|
+
static getMinNumSignatures(dataLength: number): number {
|
|
23
|
+
return Loader.getMinNumSignatures(dataLength);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Load a BPF program
|
|
28
|
+
*
|
|
29
|
+
* @param connection The connection to use
|
|
30
|
+
* @param payer Account that will pay program loading fees
|
|
31
|
+
* @param program Account to load the program into
|
|
32
|
+
* @param elf The entire ELF containing the BPF program
|
|
33
|
+
* @param loaderProgramId The program id of the BPF loader to use
|
|
34
|
+
* @return true if program was loaded successfully, false if program was already loaded
|
|
35
|
+
*/
|
|
36
|
+
static load(
|
|
37
|
+
connection: Connection,
|
|
38
|
+
payer: Signer,
|
|
39
|
+
program: Signer,
|
|
40
|
+
elf: Buffer | Uint8Array | Array<number>,
|
|
41
|
+
loaderProgramId: PublicKey,
|
|
42
|
+
): Promise<boolean> {
|
|
43
|
+
return Loader.load(connection, payer, program, loaderProgramId, elf);
|
|
44
|
+
}
|
|
45
|
+
}
|