@provablehq/sdk 0.8.7 → 0.8.8

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.
@@ -1,20 +1,21 @@
1
- import { Address, ComputeKey, PrivateKey, Signature, ViewKey, PrivateKeyCiphertext, RecordCiphertext } from "./wasm";
1
+ import { Address, ComputeKey, PrivateKey, Signature, ViewKey, PrivateKeyCiphertext, RecordCiphertext, RecordPlaintext } from "./wasm";
2
2
  interface AccountParam {
3
3
  privateKey?: string;
4
4
  seed?: Uint8Array;
5
5
  }
6
6
  /**
7
7
  * Key Management class. Enables the creation of a new Aleo Account, importation of an existing account from
8
- * an existing private key or seed, and message signing and verification functionality.
9
- *
10
- * An Aleo Account is generated from a randomly generated seed (number) from which an account private key, view key,
11
- * and a public account address are derived. The private key lies at the root of an Aleo account. It is a highly
12
- * sensitive secret and should be protected as it allows for creation of Aleo Program executions and arbitrary value
13
- * transfers. The View Key allows for decryption of a user's activity on the blockchain. The Address is the public
14
- * address to which other users of Aleo can send Aleo credits and other records to. This class should only be used
15
- * environments where the safety of the underlying key material can be assured.
8
+ * an existing private key or seed, and message signing and verification functionality. An Aleo Account is generated
9
+ * from a randomly generated seed (number) from which an account private key, view key, and a public account address are
10
+ * derived. The private key lies at the root of an Aleo account. It is a highly sensitive secret and should be protected
11
+ * as it allows for creation of Aleo Program executions and arbitrary value transfers. The View Key allows for decryption
12
+ * of a user's activity on the blockchain. The Address is the public address to which other users of Aleo can send Aleo
13
+ * credits and other records to. This class should only be used in environments where the safety of the underlying key
14
+ * material can be assured.
16
15
  *
17
16
  * @example
17
+ * import { Account } from "@provablehq/sdk/testnet.js";
18
+ *
18
19
  * // Create a new account
19
20
  * const myRandomAccount = new Account();
20
21
  *
@@ -23,14 +24,14 @@ interface AccountParam {
23
24
  * const mySeededAccount = new Account({seed: seed});
24
25
  *
25
26
  * // Create an account from an existing private key
26
- * const myExistingAccount = new Account({privateKey: 'myExistingPrivateKey'})
27
+ * const myExistingAccount = new Account({privateKey: process.env.privateKey});
27
28
  *
28
29
  * // Sign a message
29
- * const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
30
- * const signature = myRandomAccount.sign(hello_world)
30
+ * const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100]);
31
+ * const signature = myRandomAccount.sign(hello_world);
31
32
  *
32
33
  * // Verify a signature
33
- * myRandomAccount.verify(hello_world, signature)
34
+ * assert(myRandomAccount.verify(hello_world, signature));
34
35
  */
35
36
  export declare class Account {
36
37
  _privateKey: PrivateKey;
@@ -40,101 +41,217 @@ export declare class Account {
40
41
  constructor(params?: AccountParam);
41
42
  /**
42
43
  * Attempts to create an account from a private key ciphertext
43
- * @param {PrivateKeyCiphertext | string} ciphertext
44
- * @param {string} password
45
- * @returns {PrivateKey}
44
+ * @param {PrivateKeyCiphertext | string} ciphertext The encrypted private key ciphertext or its string representation
45
+ * @param {string} password The password used to decrypt the private key ciphertext
46
+ * @returns {Account} A new Account instance created from the decrypted private key
46
47
  *
47
48
  * @example
48
- * const ciphertext = PrivateKey.newEncrypted("password");
49
+ * import { Account } from "@provablehq/sdk/testnet.js";
50
+ *
51
+ * // Create an account object from a previously encrypted ciphertext and password.
49
52
  * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
50
53
  */
51
54
  static fromCiphertext(ciphertext: PrivateKeyCiphertext | string, password: string): Account;
55
+ /**
56
+ * Creates a PrivateKey from the provided parameters.
57
+ * @param {AccountParam} params The parameters containing either a private key string or a seed
58
+ * @returns {PrivateKey} A PrivateKey instance derived from the provided parameters
59
+ */
52
60
  private privateKeyFromParams;
61
+ /**
62
+ * Returns the PrivateKey associated with the account.
63
+ * @returns {PrivateKey} The private key of the account
64
+ *
65
+ * @example
66
+ * import { Account } from "@provablehq/sdk/testnet.js";
67
+ *
68
+ * const account = new Account();
69
+ * const privateKey = account.privateKey();
70
+ */
53
71
  privateKey(): PrivateKey;
72
+ /**
73
+ * Returns the ViewKey associated with the account.
74
+ * @returns {ViewKey} The view key of the account
75
+ *
76
+ * @example
77
+ * import { Account } from "@provablehq/sdk/testnet.js";
78
+ *
79
+ * const account = new Account();
80
+ * const viewKey = account.viewKey();
81
+ */
54
82
  viewKey(): ViewKey;
83
+ /**
84
+ * Returns the ComputeKey associated with the account.
85
+ * @returns {ComputeKey} The compute key of the account
86
+ *
87
+ * @example
88
+ * import { Account } from "@provablehq/sdk/testnet.js";
89
+ *
90
+ * const account = new Account();
91
+ * const computeKey = account.computeKey();
92
+ */
55
93
  computeKey(): ComputeKey;
94
+ /**
95
+ * Returns the Aleo address associated with the account.
96
+ * @returns {Address} The public address of the account
97
+ *
98
+ * @example
99
+ * import { Account } from "@provablehq/sdk/testnet.js";
100
+ *
101
+ * const account = new Account();
102
+ * const address = account.address();
103
+ */
56
104
  address(): Address;
105
+ /**
106
+ * Deep clones the Account.
107
+ * @returns {Account} A new Account instance with the same private key
108
+ *
109
+ * @example
110
+ * import { Account } from "@provablehq/sdk/testnet.js";
111
+ *
112
+ * const account = new Account();
113
+ * const clonedAccount = account.clone();
114
+ */
57
115
  clone(): Account;
58
- toString(): any;
59
116
  /**
60
- * Encrypt the account's private key with a password
61
- * @param {string} ciphertext
62
- * @returns {PrivateKeyCiphertext}
117
+ * Returns the address of the account in a string representation.
118
+ *
119
+ * @returns {string} The string representation of the account address
120
+ */
121
+ toString(): string;
122
+ /**
123
+ * Encrypts the account's private key with a password.
124
+ *
125
+ * @param {string} password Password to encrypt the private key.
126
+ * @returns {PrivateKeyCiphertext} The encrypted private key ciphertext
63
127
  *
64
128
  * @example
129
+ * import { Account } from "@provablehq/sdk/testnet.js";
130
+ *
65
131
  * const account = new Account();
66
132
  * const ciphertext = account.encryptAccount("password");
133
+ * process.env.ciphertext = ciphertext.toString();
67
134
  */
68
- encryptAccount(password: string): any;
135
+ encryptAccount(password: string): PrivateKeyCiphertext;
69
136
  /**
70
- * Decrypts a Record in ciphertext form into plaintext
71
- * @param {string} ciphertext
72
- * @returns {Record}
137
+ * Decrypts an encrypted record string into a plaintext record object.
138
+ *
139
+ * @param {string} ciphertext A string representing the ciphertext of a record.
140
+ * @returns {RecordPlaintext} The decrypted record plaintext
73
141
  *
74
142
  * @example
75
- * const account = new Account();
76
- * const record = account.decryptRecord("record1ciphertext");
143
+ * // Import the AleoNetworkClient and Account classes
144
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
145
+ *
146
+ * // Create a connection to the Aleo network and an account
147
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
148
+ * const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
149
+ *
150
+ * // Get the record ciphertexts from a transaction.
151
+ * const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
152
+ * const records = transaction.records();
153
+ *
154
+ * // Decrypt any records the account owns.
155
+ * const decryptedRecords = [];
156
+ * for (const record of records) {
157
+ * if (account.decryptRecord(record)) {
158
+ * decryptedRecords.push(record);
159
+ * }
160
+ * }
77
161
  */
78
- decryptRecord(ciphertext: string): any;
162
+ decryptRecord(ciphertext: string): RecordPlaintext;
79
163
  /**
80
- * Decrypts an array of Records in ciphertext form into plaintext
81
- * @param {string[]} ciphertexts
82
- * @returns {Record[]}
164
+ * Decrypts an array of Record ciphertext strings into an array of record plaintext objects.
165
+ *
166
+ * @param {string[]} ciphertexts An array of strings representing the ciphertexts of records.
167
+ * @returns {RecordPlaintext[]} An array of decrypted record plaintexts
83
168
  *
84
169
  * @example
85
- * const account = new Account();
86
- * const record = account.decryptRecords(["record1ciphertext", "record2ciphertext"]);
170
+ * // Import the AleoNetworkClient and Account classes
171
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
172
+ *
173
+ * // Create a connection to the Aleo network and an account
174
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
175
+ * const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
176
+ *
177
+ * // Get the record ciphertexts from a transaction.
178
+ * const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
179
+ * const records = transaction.records();
180
+ *
181
+ * // Decrypt any records the account owns. If the account owns no records, the array will be empty.
182
+ * const decryptedRecords = account.decryptRecords(records);
87
183
  */
88
- decryptRecords(ciphertexts: string[]): any[];
184
+ decryptRecords(ciphertexts: string[]): RecordPlaintext[];
89
185
  /**
90
- * Determines whether the account owns a ciphertext record
91
- * @param {RecordCipherText | string} ciphertext
92
- * @returns {boolean}
186
+ * Determines whether the account owns a ciphertext record.
187
+ * @param {RecordCiphertext | string} ciphertext The record ciphertext to check ownership of
188
+ * @returns {boolean} True if the account owns the record, false otherwise
93
189
  *
94
190
  * @example
191
+ * // Import the AleoNetworkClient and Account classes
192
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
193
+ *
95
194
  * // Create a connection to the Aleo network and an account
96
- * const connection = new AleoNetworkClient("https://api.explorer.provable.com/v1");
97
- * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
195
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
196
+ * const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
98
197
  *
99
- * // Get a record from the network
100
- * const record = connection.getBlock(1234);
101
- * const recordCipherText = record.transactions[0].execution.transitions[0].id;
198
+ * // Get the record ciphertexts from a transaction and check ownership of them.
199
+ * const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
200
+ * const records = transaction.records();
102
201
  *
103
- * // Check if the account owns the record
104
- * if account.ownsRecord(recordCipherText) {
105
- * // Then one can do something like:
106
- * // Decrypt the record and check if it's spent
107
- * // Store the record in a local database
108
- * // Etc.
202
+ * // Check if the account owns any of the record ciphertexts present in the transaction.
203
+ * const ownedRecords = [];
204
+ * for (const record of records) {
205
+ * if (account.ownsRecordCiphertext(record)) {
206
+ * ownedRecords.push(record);
207
+ * }
109
208
  * }
110
209
  */
111
- ownsRecordCiphertext(ciphertext: RecordCiphertext | string): any;
210
+ ownsRecordCiphertext(ciphertext: RecordCiphertext | string): boolean;
112
211
  /**
113
212
  * Signs a message with the account's private key.
114
213
  * Returns a Signature.
115
214
  *
116
- * @param {Uint8Array} message
117
- * @returns {Signature}
215
+ * @param {Uint8Array} message Message to be signed.
216
+ * @returns {Signature} Signature over the message in bytes.
118
217
  *
119
218
  * @example
219
+ * // Import the Account class
220
+ * import { Account } from "@provablehq/sdk/testnet.js";
221
+ *
222
+ * // Create a connection to the Aleo network and an account
223
+ * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
224
+ *
225
+ * // Create an account and a message to sign.
120
226
  * const account = new Account();
121
227
  * const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
122
- * account.sign(message);
228
+ * const signature = account.sign(message);
229
+ *
230
+ * // Verify the signature.
231
+ * assert(account.verify(message, signature));
123
232
  */
124
- sign(message: Uint8Array): any;
233
+ sign(message: Uint8Array): Signature;
125
234
  /**
126
235
  * Verifies the Signature on a message.
127
236
  *
128
- * @param {Uint8Array} message
129
- * @param {Signature} signature
130
- * @returns {boolean}
237
+ * @param {Uint8Array} message Message in bytes to be signed.
238
+ * @param {Signature} signature Signature to be verified.
239
+ * @returns {boolean} True if the signature is valid, false otherwise.
131
240
  *
132
241
  * @example
133
- * const account = new Account();
242
+ * // Import the Account class
243
+ * import { Account } from "@provablehq/sdk/testnet.js";
244
+ *
245
+ * // Create a connection to the Aleo network and an account
246
+ * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
247
+ *
248
+ * // Sign a message.
134
249
  * const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
135
250
  * const signature = account.sign(message);
136
- * account.verify(message, signature);
251
+ *
252
+ * // Verify the signature.
253
+ * assert(account.verify(message, signature));
137
254
  */
138
- verify(message: Uint8Array, signature: Signature): any;
255
+ verify(message: Uint8Array, signature: Signature): boolean;
139
256
  }
140
257
  export {};
@@ -1,22 +1,23 @@
1
1
  import 'core-js/proposals/json-parse-with-source.js';
2
2
  import { ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, ProvingKey, VerifyingKey } from '@provablehq/wasm/mainnet.js';
3
3
  export { Address, BHP1024, BHP256, BHP512, BHP768, Ciphertext, ComputeKey, ExecutionResponse, Field, Execution as FunctionExecution, Group, OfflineQuery, Pedersen128, Pedersen64, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
4
- import { C as CREDITS_PROGRAM_KEYS, c as PRIVATE_TRANSFER, d as PRIVATE_TO_PUBLIC_TRANSFER, f as PUBLIC_TRANSFER, g as PUBLIC_TRANSFER_AS_SIGNER, h as PUBLIC_TO_PRIVATE_TRANSFER, l as logAndThrow } from './program-manager-D0WpABBc.js';
5
- export { A as AleoKeyProvider, a as AleoKeyProviderParams, b as AleoNetworkClient, K as KEY_STORE, e as PRIVATE_TRANSFER_TYPES, P as ProgramManager, V as VALID_TRANSFER_TYPES } from './program-manager-D0WpABBc.js';
4
+ import { C as CREDITS_PROGRAM_KEYS, c as PRIVATE_TRANSFER, d as PRIVATE_TO_PUBLIC_TRANSFER, f as PUBLIC_TRANSFER, g as PUBLIC_TRANSFER_AS_SIGNER, h as PUBLIC_TO_PRIVATE_TRANSFER, l as logAndThrow } from './program-manager-OK_mdi-y.js';
5
+ export { A as AleoKeyProvider, a as AleoKeyProviderParams, b as AleoNetworkClient, K as KEY_STORE, e as PRIVATE_TRANSFER_TYPES, P as ProgramManager, V as VALID_TRANSFER_TYPES } from './program-manager-OK_mdi-y.js';
6
6
  import { wrap } from 'comlink';
7
7
 
8
8
  /**
9
9
  * Key Management class. Enables the creation of a new Aleo Account, importation of an existing account from
10
- * an existing private key or seed, and message signing and verification functionality.
11
- *
12
- * An Aleo Account is generated from a randomly generated seed (number) from which an account private key, view key,
13
- * and a public account address are derived. The private key lies at the root of an Aleo account. It is a highly
14
- * sensitive secret and should be protected as it allows for creation of Aleo Program executions and arbitrary value
15
- * transfers. The View Key allows for decryption of a user's activity on the blockchain. The Address is the public
16
- * address to which other users of Aleo can send Aleo credits and other records to. This class should only be used
17
- * environments where the safety of the underlying key material can be assured.
10
+ * an existing private key or seed, and message signing and verification functionality. An Aleo Account is generated
11
+ * from a randomly generated seed (number) from which an account private key, view key, and a public account address are
12
+ * derived. The private key lies at the root of an Aleo account. It is a highly sensitive secret and should be protected
13
+ * as it allows for creation of Aleo Program executions and arbitrary value transfers. The View Key allows for decryption
14
+ * of a user's activity on the blockchain. The Address is the public address to which other users of Aleo can send Aleo
15
+ * credits and other records to. This class should only be used in environments where the safety of the underlying key
16
+ * material can be assured.
18
17
  *
19
18
  * @example
19
+ * import { Account } from "@provablehq/sdk/testnet.js";
20
+ *
20
21
  * // Create a new account
21
22
  * const myRandomAccount = new Account();
22
23
  *
@@ -25,14 +26,14 @@ import { wrap } from 'comlink';
25
26
  * const mySeededAccount = new Account({seed: seed});
26
27
  *
27
28
  * // Create an account from an existing private key
28
- * const myExistingAccount = new Account({privateKey: 'myExistingPrivateKey'})
29
+ * const myExistingAccount = new Account({privateKey: process.env.privateKey});
29
30
  *
30
31
  * // Sign a message
31
- * const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
32
- * const signature = myRandomAccount.sign(hello_world)
32
+ * const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100]);
33
+ * const signature = myRandomAccount.sign(hello_world);
33
34
  *
34
35
  * // Verify a signature
35
- * myRandomAccount.verify(hello_world, signature)
36
+ * assert(myRandomAccount.verify(hello_world, signature));
36
37
  */
37
38
  class Account {
38
39
  _privateKey;
@@ -53,12 +54,14 @@ class Account {
53
54
  }
54
55
  /**
55
56
  * Attempts to create an account from a private key ciphertext
56
- * @param {PrivateKeyCiphertext | string} ciphertext
57
- * @param {string} password
58
- * @returns {PrivateKey}
57
+ * @param {PrivateKeyCiphertext | string} ciphertext The encrypted private key ciphertext or its string representation
58
+ * @param {string} password The password used to decrypt the private key ciphertext
59
+ * @returns {Account} A new Account instance created from the decrypted private key
59
60
  *
60
61
  * @example
61
- * const ciphertext = PrivateKey.newEncrypted("password");
62
+ * import { Account } from "@provablehq/sdk/testnet.js";
63
+ *
64
+ * // Create an account object from a previously encrypted ciphertext and password.
62
65
  * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
63
66
  */
64
67
  static fromCiphertext(ciphertext, password) {
@@ -71,6 +74,11 @@ class Account {
71
74
  throw new Error("Wrong password or invalid ciphertext");
72
75
  }
73
76
  }
77
+ /**
78
+ * Creates a PrivateKey from the provided parameters.
79
+ * @param {AccountParam} params The parameters containing either a private key string or a seed
80
+ * @returns {PrivateKey} A PrivateKey instance derived from the provided parameters
81
+ */
74
82
  privateKeyFromParams(params) {
75
83
  if (params.seed) {
76
84
  return PrivateKey.from_seed_unchecked(params.seed);
@@ -80,80 +88,171 @@ class Account {
80
88
  }
81
89
  return new PrivateKey();
82
90
  }
91
+ /**
92
+ * Returns the PrivateKey associated with the account.
93
+ * @returns {PrivateKey} The private key of the account
94
+ *
95
+ * @example
96
+ * import { Account } from "@provablehq/sdk/testnet.js";
97
+ *
98
+ * const account = new Account();
99
+ * const privateKey = account.privateKey();
100
+ */
83
101
  privateKey() {
84
102
  return this._privateKey;
85
103
  }
104
+ /**
105
+ * Returns the ViewKey associated with the account.
106
+ * @returns {ViewKey} The view key of the account
107
+ *
108
+ * @example
109
+ * import { Account } from "@provablehq/sdk/testnet.js";
110
+ *
111
+ * const account = new Account();
112
+ * const viewKey = account.viewKey();
113
+ */
86
114
  viewKey() {
87
115
  return this._viewKey;
88
116
  }
117
+ /**
118
+ * Returns the ComputeKey associated with the account.
119
+ * @returns {ComputeKey} The compute key of the account
120
+ *
121
+ * @example
122
+ * import { Account } from "@provablehq/sdk/testnet.js";
123
+ *
124
+ * const account = new Account();
125
+ * const computeKey = account.computeKey();
126
+ */
89
127
  computeKey() {
90
128
  return this._computeKey;
91
129
  }
130
+ /**
131
+ * Returns the Aleo address associated with the account.
132
+ * @returns {Address} The public address of the account
133
+ *
134
+ * @example
135
+ * import { Account } from "@provablehq/sdk/testnet.js";
136
+ *
137
+ * const account = new Account();
138
+ * const address = account.address();
139
+ */
92
140
  address() {
93
141
  return this._address;
94
142
  }
143
+ /**
144
+ * Deep clones the Account.
145
+ * @returns {Account} A new Account instance with the same private key
146
+ *
147
+ * @example
148
+ * import { Account } from "@provablehq/sdk/testnet.js";
149
+ *
150
+ * const account = new Account();
151
+ * const clonedAccount = account.clone();
152
+ */
95
153
  clone() {
96
154
  return new Account({ privateKey: this._privateKey.to_string() });
97
155
  }
156
+ /**
157
+ * Returns the address of the account in a string representation.
158
+ *
159
+ * @returns {string} The string representation of the account address
160
+ */
98
161
  toString() {
99
162
  return this.address().to_string();
100
163
  }
101
164
  /**
102
- * Encrypt the account's private key with a password
103
- * @param {string} ciphertext
104
- * @returns {PrivateKeyCiphertext}
165
+ * Encrypts the account's private key with a password.
166
+ *
167
+ * @param {string} password Password to encrypt the private key.
168
+ * @returns {PrivateKeyCiphertext} The encrypted private key ciphertext
105
169
  *
106
170
  * @example
171
+ * import { Account } from "@provablehq/sdk/testnet.js";
172
+ *
107
173
  * const account = new Account();
108
174
  * const ciphertext = account.encryptAccount("password");
175
+ * process.env.ciphertext = ciphertext.toString();
109
176
  */
110
177
  encryptAccount(password) {
111
178
  return this._privateKey.toCiphertext(password);
112
179
  }
113
180
  /**
114
- * Decrypts a Record in ciphertext form into plaintext
115
- * @param {string} ciphertext
116
- * @returns {Record}
181
+ * Decrypts an encrypted record string into a plaintext record object.
182
+ *
183
+ * @param {string} ciphertext A string representing the ciphertext of a record.
184
+ * @returns {RecordPlaintext} The decrypted record plaintext
117
185
  *
118
186
  * @example
119
- * const account = new Account();
120
- * const record = account.decryptRecord("record1ciphertext");
187
+ * // Import the AleoNetworkClient and Account classes
188
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
189
+ *
190
+ * // Create a connection to the Aleo network and an account
191
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
192
+ * const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
193
+ *
194
+ * // Get the record ciphertexts from a transaction.
195
+ * const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
196
+ * const records = transaction.records();
197
+ *
198
+ * // Decrypt any records the account owns.
199
+ * const decryptedRecords = [];
200
+ * for (const record of records) {
201
+ * if (account.decryptRecord(record)) {
202
+ * decryptedRecords.push(record);
203
+ * }
204
+ * }
121
205
  */
122
206
  decryptRecord(ciphertext) {
123
207
  return this._viewKey.decrypt(ciphertext);
124
208
  }
125
209
  /**
126
- * Decrypts an array of Records in ciphertext form into plaintext
127
- * @param {string[]} ciphertexts
128
- * @returns {Record[]}
210
+ * Decrypts an array of Record ciphertext strings into an array of record plaintext objects.
211
+ *
212
+ * @param {string[]} ciphertexts An array of strings representing the ciphertexts of records.
213
+ * @returns {RecordPlaintext[]} An array of decrypted record plaintexts
129
214
  *
130
215
  * @example
131
- * const account = new Account();
132
- * const record = account.decryptRecords(["record1ciphertext", "record2ciphertext"]);
216
+ * // Import the AleoNetworkClient and Account classes
217
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
218
+ *
219
+ * // Create a connection to the Aleo network and an account
220
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
221
+ * const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
222
+ *
223
+ * // Get the record ciphertexts from a transaction.
224
+ * const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
225
+ * const records = transaction.records();
226
+ *
227
+ * // Decrypt any records the account owns. If the account owns no records, the array will be empty.
228
+ * const decryptedRecords = account.decryptRecords(records);
133
229
  */
134
230
  decryptRecords(ciphertexts) {
135
231
  return ciphertexts.map((ciphertext) => this._viewKey.decrypt(ciphertext));
136
232
  }
137
233
  /**
138
- * Determines whether the account owns a ciphertext record
139
- * @param {RecordCipherText | string} ciphertext
140
- * @returns {boolean}
234
+ * Determines whether the account owns a ciphertext record.
235
+ * @param {RecordCiphertext | string} ciphertext The record ciphertext to check ownership of
236
+ * @returns {boolean} True if the account owns the record, false otherwise
141
237
  *
142
238
  * @example
239
+ * // Import the AleoNetworkClient and Account classes
240
+ * import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
241
+ *
143
242
  * // Create a connection to the Aleo network and an account
144
- * const connection = new AleoNetworkClient("https://api.explorer.provable.com/v1");
145
- * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
243
+ * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
244
+ * const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
146
245
  *
147
- * // Get a record from the network
148
- * const record = connection.getBlock(1234);
149
- * const recordCipherText = record.transactions[0].execution.transitions[0].id;
246
+ * // Get the record ciphertexts from a transaction and check ownership of them.
247
+ * const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
248
+ * const records = transaction.records();
150
249
  *
151
- * // Check if the account owns the record
152
- * if account.ownsRecord(recordCipherText) {
153
- * // Then one can do something like:
154
- * // Decrypt the record and check if it's spent
155
- * // Store the record in a local database
156
- * // Etc.
250
+ * // Check if the account owns any of the record ciphertexts present in the transaction.
251
+ * const ownedRecords = [];
252
+ * for (const record of records) {
253
+ * if (account.ownsRecordCiphertext(record)) {
254
+ * ownedRecords.push(record);
255
+ * }
157
256
  * }
158
257
  */
159
258
  ownsRecordCiphertext(ciphertext) {
@@ -174,13 +273,23 @@ class Account {
174
273
  * Signs a message with the account's private key.
175
274
  * Returns a Signature.
176
275
  *
177
- * @param {Uint8Array} message
178
- * @returns {Signature}
276
+ * @param {Uint8Array} message Message to be signed.
277
+ * @returns {Signature} Signature over the message in bytes.
179
278
  *
180
279
  * @example
280
+ * // Import the Account class
281
+ * import { Account } from "@provablehq/sdk/testnet.js";
282
+ *
283
+ * // Create a connection to the Aleo network and an account
284
+ * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
285
+ *
286
+ * // Create an account and a message to sign.
181
287
  * const account = new Account();
182
288
  * const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
183
- * account.sign(message);
289
+ * const signature = account.sign(message);
290
+ *
291
+ * // Verify the signature.
292
+ * assert(account.verify(message, signature));
184
293
  */
185
294
  sign(message) {
186
295
  return this._privateKey.sign(message);
@@ -188,15 +297,23 @@ class Account {
188
297
  /**
189
298
  * Verifies the Signature on a message.
190
299
  *
191
- * @param {Uint8Array} message
192
- * @param {Signature} signature
193
- * @returns {boolean}
300
+ * @param {Uint8Array} message Message in bytes to be signed.
301
+ * @param {Signature} signature Signature to be verified.
302
+ * @returns {boolean} True if the signature is valid, false otherwise.
194
303
  *
195
304
  * @example
196
- * const account = new Account();
305
+ * // Import the Account class
306
+ * import { Account } from "@provablehq/sdk/testnet.js";
307
+ *
308
+ * // Create a connection to the Aleo network and an account
309
+ * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
310
+ *
311
+ * // Sign a message.
197
312
  * const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
198
313
  * const signature = account.sign(message);
199
- * account.verify(message, signature);
314
+ *
315
+ * // Verify the signature.
316
+ * assert(account.verify(message, signature));
200
317
  */
201
318
  verify(message, signature) {
202
319
  return this._address.verify(message, signature);