}\r
set weight (v) { this.#weight = v ? BigInt(v) : undefined }\r
\r
- private constructor (address: string, publicKey: Uint8Array<ArrayBuffer>, index?: number) {\r
+ private constructor (address: string, publicKey: Key, index?: number) {\r
if (!Account.#isInternal) {\r
throw new Error(`Account cannot be instantiated directly. Use factory methods instead.`)\r
}\r
this.#address = address\r
.replace(PREFIX, '')\r
.replace(PREFIX_LEGACY, '')\r
- this.#publicKey = publicKey\r
+ this.#publicKey = typeof publicKey === 'string'\r
+ ? hex.toBytes(publicKey)\r
+ : publicKey\r
this.#index = index\r
}\r
\r
*/\r
async destroy (): Promise<void> {\r
await SafeWorker.assign({\r
- store: 'Account',\r
method: 'destroy',\r
- name: this.#publicKey\r
+ name: this.publicKey,\r
+ store: 'Account'\r
})\r
this.#frontier = undefined\r
this.#balance = undefined\r
}\r
\r
const accounts: Account[] = []\r
- const data: Data = {}\r
+ const privateAccounts: Data = {}\r
for (let keypair of keypairs) {\r
let { index, privateKey } = keypair\r
if (index == null) {\r
if (typeof privateKey === 'string') privateKey = hex.toBytes(privateKey)\r
try {\r
const headers = {\r
- method: 'convert',\r
- privateKey: privateKey.buffer\r
+ method: 'convert'\r
}\r
- const publicKey = await NanoNaClWorker.assign(headers)\r
- data[publicKey] = privateKey.buffer\r
-\r
- const address = this.#keyToAddress(publicKey)\r
+ const data = {\r
+ privateKey: new Uint8Array(privateKey).buffer\r
+ }\r
+ const publicKey = await NanoNaClWorker.assign(headers, data)\r
+ privateAccounts[publicKey] = privateKey.buffer\r
+ const address = this.#keyToAddress(hex.toBytes(publicKey))\r
this.#isInternal = true\r
+ debugger\r
accounts.push(new this(address, publicKey, index))\r
} catch (err) {\r
throw new Error(`Failed to derive public key from private key`, { cause: err })\r
method: 'set',\r
store: 'Account'\r
}\r
- data.password = password.buffer\r
- const isLocked = await SafeWorker.assign(headers, data)\r
+ privateAccounts.password = password.buffer\r
+ const isLocked = await SafeWorker.assign(headers, privateAccounts)\r
if (!isLocked) {\r
throw null\r
}\r