@solana/web3.js 1.11.1 → 1.12.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.esm.js +66 -15
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +68 -14
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +21 -2
- package/lib/index.esm.js +66 -15
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +1103 -14
- 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/module.flow.js +21 -4
- package/package.json +2 -1
- package/src/index.ts +1 -0
- package/src/publickey.ts +41 -13
- package/src/util/borsh-schema.ts +34 -0
package/lib/index.cjs.js
CHANGED
|
@@ -8,6 +8,7 @@ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
|
8
8
|
var BN = require('bn.js');
|
|
9
9
|
var bs58 = require('bs58');
|
|
10
10
|
var cryptoHash = require('crypto-hash');
|
|
11
|
+
var borsh = require('borsh');
|
|
11
12
|
var BufferLayout = require('buffer-layout');
|
|
12
13
|
var invariant = require('assert');
|
|
13
14
|
var url = require('url');
|
|
@@ -65,16 +66,55 @@ const toBuffer = arr => {
|
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
68
|
|
|
69
|
+
class Struct {
|
|
70
|
+
constructor(properties) {
|
|
71
|
+
Object.assign(this, properties);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
encode() {
|
|
75
|
+
return buffer.Buffer.from(borsh.serialize(SOLANA_SCHEMA, this));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static decode(data) {
|
|
79
|
+
return borsh.deserialize(SOLANA_SCHEMA, this, data);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
} // Class representing a Rust-compatible enum, since enums are only strings or
|
|
83
|
+
// numbers in pure JS
|
|
84
|
+
|
|
85
|
+
class Enum extends Struct {
|
|
86
|
+
constructor(properties) {
|
|
87
|
+
super(properties);
|
|
88
|
+
|
|
89
|
+
_defineProperty__default['default'](this, "enum", '');
|
|
90
|
+
|
|
91
|
+
if (Object.keys(properties).length !== 1) {
|
|
92
|
+
throw new Error('Enum can only take single value');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
Object.keys(properties).map(key => {
|
|
96
|
+
this.enum = key;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
const SOLANA_SCHEMA = new Map();
|
|
102
|
+
|
|
68
103
|
/**
|
|
69
104
|
* Maximum length of derived pubkey seed
|
|
70
105
|
*/
|
|
71
106
|
|
|
72
107
|
const MAX_SEED_LENGTH = 32;
|
|
108
|
+
|
|
109
|
+
function isPublicKeyData(value) {
|
|
110
|
+
return value._bn !== undefined;
|
|
111
|
+
}
|
|
73
112
|
/**
|
|
74
113
|
* A public key
|
|
75
114
|
*/
|
|
76
115
|
|
|
77
|
-
|
|
116
|
+
|
|
117
|
+
class PublicKey extends Struct {
|
|
78
118
|
/** @internal */
|
|
79
119
|
|
|
80
120
|
/**
|
|
@@ -82,21 +122,27 @@ class PublicKey {
|
|
|
82
122
|
* @param value ed25519 public key as buffer or base-58 encoded string
|
|
83
123
|
*/
|
|
84
124
|
constructor(value) {
|
|
85
|
-
|
|
86
|
-
// assume base 58 encoding by default
|
|
87
|
-
const decoded = bs58__default['default'].decode(value);
|
|
88
|
-
|
|
89
|
-
if (decoded.length != 32) {
|
|
90
|
-
throw new Error("Invalid public key input");
|
|
91
|
-
}
|
|
125
|
+
super({});
|
|
92
126
|
|
|
93
|
-
|
|
127
|
+
if (isPublicKeyData(value)) {
|
|
128
|
+
this._bn = value._bn;
|
|
94
129
|
} else {
|
|
95
|
-
|
|
96
|
-
|
|
130
|
+
if (typeof value === 'string') {
|
|
131
|
+
// assume base 58 encoding by default
|
|
132
|
+
const decoded = bs58__default['default'].decode(value);
|
|
133
|
+
|
|
134
|
+
if (decoded.length != 32) {
|
|
135
|
+
throw new Error("Invalid public key input");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this._bn = new BN__default['default'](decoded);
|
|
139
|
+
} else {
|
|
140
|
+
this._bn = new BN__default['default'](value);
|
|
141
|
+
}
|
|
97
142
|
|
|
98
|
-
|
|
99
|
-
|
|
143
|
+
if (this._bn.byteLength() > 32) {
|
|
144
|
+
throw new Error("Invalid public key input");
|
|
145
|
+
}
|
|
100
146
|
}
|
|
101
147
|
}
|
|
102
148
|
/**
|
|
@@ -224,10 +270,15 @@ class PublicKey {
|
|
|
224
270
|
return is_on_curve(pubkey) == 1;
|
|
225
271
|
}
|
|
226
272
|
|
|
227
|
-
}
|
|
273
|
+
}
|
|
228
274
|
|
|
229
275
|
_defineProperty__default['default'](PublicKey, "default", new PublicKey('11111111111111111111111111111111'));
|
|
230
276
|
|
|
277
|
+
SOLANA_SCHEMA.set(PublicKey, {
|
|
278
|
+
kind: 'struct',
|
|
279
|
+
fields: [['_bn', 'u256']]
|
|
280
|
+
}); // @ts-ignore
|
|
281
|
+
|
|
231
282
|
let naclLowLevel = nacl__default['default'].lowlevel; // Check that a pubkey is on the curve.
|
|
232
283
|
// This function and its dependents were sourced from:
|
|
233
284
|
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
@@ -6342,6 +6393,7 @@ exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
|
|
|
6342
6393
|
exports.BPF_LOADER_PROGRAM_ID = BPF_LOADER_PROGRAM_ID;
|
|
6343
6394
|
exports.BpfLoader = BpfLoader;
|
|
6344
6395
|
exports.Connection = Connection;
|
|
6396
|
+
exports.Enum = Enum;
|
|
6345
6397
|
exports.FeeCalculatorLayout = FeeCalculatorLayout;
|
|
6346
6398
|
exports.Keypair = Keypair;
|
|
6347
6399
|
exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
|
|
@@ -6353,6 +6405,7 @@ exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
|
|
|
6353
6405
|
exports.NonceAccount = NonceAccount;
|
|
6354
6406
|
exports.PACKET_DATA_SIZE = PACKET_DATA_SIZE;
|
|
6355
6407
|
exports.PublicKey = PublicKey;
|
|
6408
|
+
exports.SOLANA_SCHEMA = SOLANA_SCHEMA;
|
|
6356
6409
|
exports.STAKE_CONFIG_ID = STAKE_CONFIG_ID;
|
|
6357
6410
|
exports.STAKE_INSTRUCTION_LAYOUTS = STAKE_INSTRUCTION_LAYOUTS;
|
|
6358
6411
|
exports.SYSTEM_INSTRUCTION_LAYOUTS = SYSTEM_INSTRUCTION_LAYOUTS;
|
|
@@ -6366,6 +6419,7 @@ exports.Secp256k1Program = Secp256k1Program;
|
|
|
6366
6419
|
exports.StakeAuthorizationLayout = StakeAuthorizationLayout;
|
|
6367
6420
|
exports.StakeInstruction = StakeInstruction;
|
|
6368
6421
|
exports.StakeProgram = StakeProgram;
|
|
6422
|
+
exports.Struct = Struct;
|
|
6369
6423
|
exports.SystemInstruction = SystemInstruction;
|
|
6370
6424
|
exports.SystemProgram = SystemProgram;
|
|
6371
6425
|
exports.Transaction = Transaction;
|