@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.
@@ -5,6 +5,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
5
5
  import BN from 'bn.js';
6
6
  import bs58 from 'bs58';
7
7
  import { sha256 } from 'crypto-hash';
8
+ import { serialize, deserialize } from 'borsh';
8
9
  import * as BufferLayout from 'buffer-layout';
9
10
  import fetch from 'node-fetch';
10
11
  import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$1 } from 'superstruct';
@@ -23,16 +24,55 @@ const toBuffer = arr => {
23
24
  }
24
25
  };
25
26
 
27
+ class Struct {
28
+ constructor(properties) {
29
+ Object.assign(this, properties);
30
+ }
31
+
32
+ encode() {
33
+ return Buffer.from(serialize(SOLANA_SCHEMA, this));
34
+ }
35
+
36
+ static decode(data) {
37
+ return deserialize(SOLANA_SCHEMA, this, data);
38
+ }
39
+
40
+ } // Class representing a Rust-compatible enum, since enums are only strings or
41
+ // numbers in pure JS
42
+
43
+ class Enum extends Struct {
44
+ constructor(properties) {
45
+ super(properties);
46
+
47
+ _defineProperty(this, "enum", '');
48
+
49
+ if (Object.keys(properties).length !== 1) {
50
+ throw new Error('Enum can only take single value');
51
+ }
52
+
53
+ Object.keys(properties).map(key => {
54
+ this.enum = key;
55
+ });
56
+ }
57
+
58
+ }
59
+ const SOLANA_SCHEMA = new Map();
60
+
26
61
  /**
27
62
  * Maximum length of derived pubkey seed
28
63
  */
29
64
 
30
65
  const MAX_SEED_LENGTH = 32;
66
+
67
+ function isPublicKeyData(value) {
68
+ return value._bn !== undefined;
69
+ }
31
70
  /**
32
71
  * A public key
33
72
  */
34
73
 
35
- class PublicKey {
74
+
75
+ class PublicKey extends Struct {
36
76
  /** @internal */
37
77
 
38
78
  /**
@@ -40,21 +80,27 @@ class PublicKey {
40
80
  * @param value ed25519 public key as buffer or base-58 encoded string
41
81
  */
42
82
  constructor(value) {
43
- if (typeof value === 'string') {
44
- // assume base 58 encoding by default
45
- const decoded = bs58.decode(value);
46
-
47
- if (decoded.length != 32) {
48
- throw new Error("Invalid public key input");
49
- }
83
+ super({});
50
84
 
51
- this._bn = new BN(decoded);
85
+ if (isPublicKeyData(value)) {
86
+ this._bn = value._bn;
52
87
  } else {
53
- this._bn = new BN(value);
54
- }
88
+ if (typeof value === 'string') {
89
+ // assume base 58 encoding by default
90
+ const decoded = bs58.decode(value);
91
+
92
+ if (decoded.length != 32) {
93
+ throw new Error("Invalid public key input");
94
+ }
95
+
96
+ this._bn = new BN(decoded);
97
+ } else {
98
+ this._bn = new BN(value);
99
+ }
55
100
 
56
- if (this._bn.byteLength() > 32) {
57
- throw new Error("Invalid public key input");
101
+ if (this._bn.byteLength() > 32) {
102
+ throw new Error("Invalid public key input");
103
+ }
58
104
  }
59
105
  }
60
106
  /**
@@ -182,10 +228,15 @@ class PublicKey {
182
228
  return is_on_curve(pubkey) == 1;
183
229
  }
184
230
 
185
- } // @ts-ignore
231
+ }
186
232
 
187
233
  _defineProperty(PublicKey, "default", new PublicKey('11111111111111111111111111111111'));
188
234
 
235
+ SOLANA_SCHEMA.set(PublicKey, {
236
+ kind: 'struct',
237
+ fields: [['_bn', 'u256']]
238
+ }); // @ts-ignore
239
+
189
240
  let naclLowLevel = nacl__default.lowlevel; // Check that a pubkey is on the curve.
190
241
  // This function and its dependents were sourced from:
191
242
  // https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
@@ -8237,5 +8288,5 @@ function clusterApiUrl(cluster, tls) {
8237
8288
 
8238
8289
  const LAMPORTS_PER_SOL = 1000000000;
8239
8290
 
8240
- export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, StakeAuthorizationLayout, StakeInstruction, StakeProgram, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
8291
+ export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Enum, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
8241
8292
  //# sourceMappingURL=index.browser.esm.js.map