@solana/web3.js 1.26.1 → 1.27.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/module.flow.js CHANGED
@@ -23,6 +23,10 @@ declare module "@solana/web3.js" {
23
23
  * Maximum length of derived pubkey seed
24
24
  */
25
25
  declare export var MAX_SEED_LENGTH: 32;
26
+
27
+ /**
28
+ * Value to be converted into public key
29
+ */
26
30
  declare export type PublicKeyInitData =
27
31
  | number
28
32
  | string
@@ -30,6 +34,10 @@ declare module "@solana/web3.js" {
30
34
  | Uint8Array
31
35
  | Array<number>
32
36
  | PublicKeyData;
37
+
38
+ /**
39
+ * JSON object representation of PublicKey class
40
+ */
33
41
  declare export type PublicKeyData = { ... };
34
42
 
35
43
  /**
@@ -2717,6 +2725,50 @@ feeCalculator: FeeCalculator,...
2717
2725
  ): Promise<boolean>;
2718
2726
  }
2719
2727
 
2728
+ /**
2729
+ * Params for creating an ed25519 instruction using a public key
2730
+ */
2731
+ declare export type CreateEd25519InstructionWithPublicKeyParams = {
2732
+ publicKey: Uint8Array,
2733
+ message: Uint8Array,
2734
+ signature: Uint8Array,
2735
+ instructionIndex?: number,
2736
+ ...
2737
+ };
2738
+
2739
+ /**
2740
+ * Params for creating an ed25519 instruction using a private key
2741
+ */
2742
+ declare export type CreateEd25519InstructionWithPrivateKeyParams = {
2743
+ privateKey: Uint8Array,
2744
+ message: Uint8Array,
2745
+ instructionIndex?: number,
2746
+ ...
2747
+ };
2748
+ declare export class Ed25519Program {
2749
+ /**
2750
+ * Public key that identifies the ed25519 program
2751
+ */
2752
+ static programId: PublicKey;
2753
+
2754
+ /**
2755
+ * Create an ed25519 instruction with a public key and signature. The
2756
+ * public key must be a buffer that is 32 bytes long, and the signature
2757
+ * must be a buffer of 64 bytes.
2758
+ */
2759
+ static createInstructionWithPublicKey(
2760
+ params: CreateEd25519InstructionWithPublicKeyParams
2761
+ ): TransactionInstruction;
2762
+
2763
+ /**
2764
+ * Create an ed25519 instruction with a private key. The private key
2765
+ * must be a buffer that is 64 bytes long.
2766
+ */
2767
+ static createInstructionWithPrivateKey(
2768
+ params: CreateEd25519InstructionWithPrivateKeyParams
2769
+ ): TransactionInstruction;
2770
+ }
2771
+
2720
2772
  /**
2721
2773
  * Program loader interface
2722
2774
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.26.1",
3
+ "version": "1.27.1",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -101,6 +101,7 @@
101
101
  "npm-run-all": "^4.1.5",
102
102
  "nyc": "^15.1.0",
103
103
  "prettier": "^2.3.0",
104
+ "puppeteer": "^10.2.0",
104
105
  "rimraf": "3.0.2",
105
106
  "rollup": "2.56.3",
106
107
  "rollup-plugin-dts": "^4.0.0",
@@ -111,7 +112,7 @@
111
112
  "start-server-and-test": "^1.12.0",
112
113
  "ts-node": "^10.0.0",
113
114
  "tslib": "^2.1.0",
114
- "typedoc": "^0.21.0-beta.2",
115
+ "typedoc": "^0.22.2",
115
116
  "typescript": "^4.3.2"
116
117
  },
117
118
  "engines": {
@@ -124,7 +125,7 @@
124
125
  "clean": "rimraf ./coverage ./lib",
125
126
  "codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
126
127
  "dev": "cross-env NODE_ENV=development rollup -c",
127
- "doc": "set -ex; typedoc",
128
+ "doc": "set -ex; typedoc --treatWarningsAsErrors",
128
129
  "flow:check": "flow check-contents < module.flow.js",
129
130
  "flow:gen": "flowgen lib/index.d.ts -o module.flow.js",
130
131
  "type:gen": "./scripts/typegen.sh",
@@ -0,0 +1,140 @@
1
+ import {Buffer} from 'buffer';
2
+ import * as BufferLayout from '@solana/buffer-layout';
3
+ import nacl from 'tweetnacl';
4
+
5
+ import {Keypair} from './keypair';
6
+ import {PublicKey} from './publickey';
7
+ import {TransactionInstruction} from './transaction';
8
+ import assert from './util/assert';
9
+
10
+ const PRIVATE_KEY_BYTES = 64;
11
+ const PUBLIC_KEY_BYTES = 32;
12
+ const SIGNATURE_BYTES = 64;
13
+
14
+ /**
15
+ * Params for creating an ed25519 instruction using a public key
16
+ */
17
+ export type CreateEd25519InstructionWithPublicKeyParams = {
18
+ publicKey: Uint8Array;
19
+ message: Uint8Array;
20
+ signature: Uint8Array;
21
+ instructionIndex?: number;
22
+ };
23
+
24
+ /**
25
+ * Params for creating an ed25519 instruction using a private key
26
+ */
27
+ export type CreateEd25519InstructionWithPrivateKeyParams = {
28
+ privateKey: Uint8Array;
29
+ message: Uint8Array;
30
+ instructionIndex?: number;
31
+ };
32
+
33
+ const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([
34
+ BufferLayout.u8('numSignatures'),
35
+ BufferLayout.u8('padding'),
36
+ BufferLayout.u16('signatureOffset'),
37
+ BufferLayout.u16('signatureInstructionIndex'),
38
+ BufferLayout.u16('publicKeyOffset'),
39
+ BufferLayout.u16('publicKeyInstructionIndex'),
40
+ BufferLayout.u16('messageDataOffset'),
41
+ BufferLayout.u16('messageDataSize'),
42
+ BufferLayout.u16('messageInstructionIndex'),
43
+ ]);
44
+
45
+ export class Ed25519Program {
46
+ /**
47
+ * @internal
48
+ */
49
+ constructor() {}
50
+
51
+ /**
52
+ * Public key that identifies the ed25519 program
53
+ */
54
+ static programId: PublicKey = new PublicKey(
55
+ 'Ed25519SigVerify111111111111111111111111111',
56
+ );
57
+
58
+ /**
59
+ * Create an ed25519 instruction with a public key and signature. The
60
+ * public key must be a buffer that is 32 bytes long, and the signature
61
+ * must be a buffer of 64 bytes.
62
+ */
63
+ static createInstructionWithPublicKey(
64
+ params: CreateEd25519InstructionWithPublicKeyParams,
65
+ ): TransactionInstruction {
66
+ const {publicKey, message, signature, instructionIndex} = params;
67
+
68
+ assert(
69
+ publicKey.length === PUBLIC_KEY_BYTES,
70
+ `Public Key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`,
71
+ );
72
+
73
+ assert(
74
+ signature.length === SIGNATURE_BYTES,
75
+ `Signature must be ${SIGNATURE_BYTES} bytes but received ${signature.length} bytes`,
76
+ );
77
+
78
+ const publicKeyOffset = ED25519_INSTRUCTION_LAYOUT.span;
79
+ const signatureOffset = publicKeyOffset + publicKey.length;
80
+ const messageDataOffset = signatureOffset + signature.length;
81
+ const numSignatures = 1;
82
+
83
+ const instructionData = Buffer.alloc(messageDataOffset + message.length);
84
+
85
+ ED25519_INSTRUCTION_LAYOUT.encode(
86
+ {
87
+ numSignatures,
88
+ padding: 0,
89
+ signatureOffset,
90
+ signatureInstructionIndex: instructionIndex,
91
+ publicKeyOffset,
92
+ publicKeyInstructionIndex: instructionIndex,
93
+ messageDataOffset,
94
+ messageDataSize: message.length,
95
+ messageInstructionIndex: instructionIndex,
96
+ },
97
+ instructionData,
98
+ );
99
+
100
+ instructionData.fill(publicKey, publicKeyOffset);
101
+ instructionData.fill(signature, signatureOffset);
102
+ instructionData.fill(message, messageDataOffset);
103
+
104
+ return new TransactionInstruction({
105
+ keys: [],
106
+ programId: Ed25519Program.programId,
107
+ data: instructionData,
108
+ });
109
+ }
110
+
111
+ /**
112
+ * Create an ed25519 instruction with a private key. The private key
113
+ * must be a buffer that is 64 bytes long.
114
+ */
115
+ static createInstructionWithPrivateKey(
116
+ params: CreateEd25519InstructionWithPrivateKeyParams,
117
+ ): TransactionInstruction {
118
+ const {privateKey, message, instructionIndex} = params;
119
+
120
+ assert(
121
+ privateKey.length === PRIVATE_KEY_BYTES,
122
+ `Private key must be ${PRIVATE_KEY_BYTES} bytes but received ${privateKey.length} bytes`,
123
+ );
124
+
125
+ try {
126
+ const keypair = Keypair.fromSecretKey(privateKey);
127
+ const publicKey = keypair.publicKey.toBytes();
128
+ const signature = nacl.sign.detached(message, keypair.secretKey);
129
+
130
+ return this.createInstructionWithPublicKey({
131
+ publicKey,
132
+ message,
133
+ signature,
134
+ instructionIndex,
135
+ });
136
+ } catch (error) {
137
+ throw new Error(`Error creating instruction; ${error}`);
138
+ }
139
+ }
140
+ }
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ export * from './bpf-loader-deprecated';
4
4
  export * from './bpf-loader';
5
5
  export * from './connection';
6
6
  export * from './epoch-schedule';
7
+ export * from './ed25519-program';
7
8
  export * from './fee-calculator';
8
9
  export * from './keypair';
9
10
  export * from './loader';
package/src/publickey.ts CHANGED
@@ -12,7 +12,10 @@ import {toBuffer} from './util/to-buffer';
12
12
  */
13
13
  export const MAX_SEED_LENGTH = 32;
14
14
 
15
- type PublicKeyInitData =
15
+ /**
16
+ * Value to be converted into public key
17
+ */
18
+ export type PublicKeyInitData =
16
19
  | number
17
20
  | string
18
21
  | Buffer
@@ -20,7 +23,10 @@ type PublicKeyInitData =
20
23
  | Array<number>
21
24
  | PublicKeyData;
22
25
 
23
- type PublicKeyData = {
26
+ /**
27
+ * JSON object representation of PublicKey class
28
+ */
29
+ export type PublicKeyData = {
24
30
  /** @internal */
25
31
  _bn: BN;
26
32
  };
@@ -107,7 +107,7 @@ export type SignaturePubkeyPair = {
107
107
  * List of Transaction object fields that may be initialized at construction
108
108
  *
109
109
  */
110
- type TransactionCtorFields = {
110
+ export type TransactionCtorFields = {
111
111
  /** A recent blockhash */
112
112
  recentBlockhash?: Blockhash | null;
113
113
  /** Optional nonce information used for offline nonce'd transactions */
@@ -121,7 +121,7 @@ type TransactionCtorFields = {
121
121
  /**
122
122
  * Nonce information to be used to build an offline Transaction.
123
123
  */
124
- type NonceInformation = {
124
+ export type NonceInformation = {
125
125
  /** The current blockhash stored in the nonce */
126
126
  nonce: Blockhash;
127
127
  /** AdvanceNonceAccount Instruction */