delete data.encrypted
}
- // Index for child account to derive or sign
- if ((action === 'derive' || action === 'sign') && !(data.indexes instanceof ArrayBuffer)) {
+ // Index(es) for child account to derive or sign
+ if ((action === 'derive' || action === 'sign') && !(data.index instanceof ArrayBuffer)) {
throw new TypeError('Index is required to derive an account private key')
}
- const indexes = typeof data.indexes instanceof ArrayBuffer
+ const index = data.index instanceof ArrayBuffer
? new Uint32Array(data.index)
: undefined
? data.timeout
: undefined
- return { seed, mnemonicPhrase, mnemonicSalt, encrypted, index, count, message, timeout }
+ return { seed, mnemonicPhrase, mnemonicSalt, encrypted, index, message, timeout }
} catch (err) {
new Uint8Array(seed ?? []).fill(0)
new Uint8Array(encrypted ?? []).fill(0)
const id = parseId(action, data)
const iv = parseIv(action, data)
const parsed = parseData(action, data)
- const { seed, mnemonicPhrase, mnemonicSalt, indexes, encrypted, message, timeout } = parsed
+ const { seed, mnemonicPhrase, mnemonicSalt, index, encrypted, message, timeout } = parsed
passkey(action, keySalt, data)
.then((key: CryptoKey | undefined): Promise<Record<string, boolean | number | ArrayBuffer> | void> => {
switch (action) {
return create(type, id, key, keySalt, mnemonicSalt)
}
case 'derive': {
- return derive(indexes)
+ return derive(index)
}
case 'load': {
return load(type, id, key, keySalt, mnemonicPhrase ?? seed, mnemonicSalt)
* wallet seed at a specified index and then returns the public key. The wallet
* must be unlocked prior to derivation.
*/
-function derive (indexes?: Uint32Array): Promise<Record<string, number | ArrayBuffer>> {
+function derive (index?: number | Uint32Array): Promise<Record<string, number | ArrayBuffer>> {
try {
_timer.pause()
if (_locked) {
if (_type !== 'BIP-44' && _type !== 'BLAKE2b' && _type !== 'Exodus') {
throw new Error('Invalid wallet type')
}
- if (indexes == null) {
+ if (index == null) {
throw new Error('Invalid wallet account index(es)')
}
const promises = []
- const values = indexes.values()
- for (const index of values) {
- promises.push(_ckd(index).then(result => {
+ const values = typeof index === 'number' ? [index] : index.values()
+ for (const i of values) {
+ promises.push(_ckd(i).then(result => {
const prv = new Uint8Array(result)
const pub = nano25519_derive(prv)
prv.fill(0)
- return { index, publicKey: pub.buffer }
+ return { index: i, publicKey: pub.buffer }
}))
}
return Promise.all(promises)
* Derives the account private key at a specified index, signs the input data,
* and returns a signature. The wallet must be unlocked prior to verification.
*/
-function sign (index?: number, data?: ArrayBuffer): Promise<Record<string, ArrayBuffer>> {
+function sign (index?: Uint32Array, data?: ArrayBuffer): Promise<Record<string, ArrayBuffer>> {
try {
_timer.pause()
if (_locked) {
if (data == null) {
throw new Error('Data to sign not found')
}
- return _ckd(index).then(result => {
+ return _ckd(index[0]).then(result => {
const prv = new Uint8Array(result)
const pub = nano25519_derive(prv)
const sk = new Uint8Array([...prv, ...pub])