}
// Seed to load
- if (action === 'load') {
- if (data.seed == null) {
- throw new TypeError('Seed required to load wallet')
- }
+ if ('seed' in data) {
if (!(data.seed instanceof ArrayBuffer)) {
throw new TypeError('Invalid wallet seed')
}
- seed = data.seed.slice()
+ if (action === 'load') {
+ seed = data.seed.slice()
+ }
+ new Uint8Array(data.seed).fill(0)
+ delete data.seed
}
- new Uint8Array(data.seed as ArrayBuffer).fill(0)
- delete data.seed
// Mnemonic phrase to load
if (action === 'load' && 'mnemonicPhrase' in data && typeof data.mnemonicPhrase !== 'string') {
delete data.mnemonicSalt
// Encrypted seed and possibly mnemonic
- if (action === 'unlock') {
- if (data.encrypted == null) {
- throw new TypeError('Wallet encrypted secrets not found')
- }
- if (!(data.encrypted instanceof ArrayBuffer)) {
+ if ('encrypted' in data) {
+ if (action === 'unlock') {
+ if (!(data.encrypted instanceof ArrayBuffer)) {
throw new TypeError('Invalid wallet encrypted secrets')
+ }
+ encrypted = data.encrypted.slice()
}
- encrypted = data.encrypted.slice()
+ new Uint8Array(data.encrypted as ArrayBuffer).fill(0)
+ delete data.encrypted
}
- new Uint8Array(data.encrypted as ArrayBuffer).fill(0)
- delete data.encrypted
// Index for child account to derive or sign
if ((action === 'derive' || action === 'sign') && typeof data.index !== 'number') {
: undefined
// Data to sign
- if (action === 'sign') {
- if (data.message == null) {
- throw new TypeError('Data to sign not found')
+ if ('message' in data) {
+ if (action === 'sign') {
+ if (!(data.message instanceof ArrayBuffer)) {
+ throw new TypeError('Invalid data to sign')
+ }
+ message = data.message.slice()
}
- if (!(data.message instanceof ArrayBuffer)) {
- throw new TypeError('Invalid data to sign')
- }
- message = data.message.slice()
- }
- new Uint8Array(data.message as ArrayBuffer).fill(0)
- delete data.message
+ new Uint8Array(data.message as ArrayBuffer).fill(0)
+ delete data.message
+ }
// Vault configuration
if (action === 'config') {