Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/abstract-eth/src/abstractEthLikeNewCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {

if (!userKey.startsWith('xpub') && !userKey.startsWith('xprv')) {
try {
userKey = this.bitgo.decrypt({
userKey = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -1497,7 +1497,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
let backupPrv;

try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down Expand Up @@ -1670,7 +1670,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {

let userKeyPrv;
try {
userKeyPrv = this.bitgo.decrypt({
userKeyPrv = await this.bitgo.decryptAsync({
input: params.encryptedPrv,
password: params.walletPassphrase,
});
Expand Down Expand Up @@ -1749,7 +1749,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
if (params.walletPassphrase) {
if (!userKey.startsWith('xpub') && !userKey.startsWith('xprv')) {
try {
userKeyPrv = this.bitgo.decrypt({
userKeyPrv = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand Down
4 changes: 2 additions & 2 deletions modules/abstract-eth/src/ethLikeToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class EthLikeToken extends AbstractEthLikeNewCoins {
// Decrypt private keys from KeyCard values
if (!userKey.startsWith('xpub') && !userKey.startsWith('xprv')) {
try {
userKey = this.bitgo.decrypt({
userKey = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -239,7 +239,7 @@ export class EthLikeToken extends AbstractEthLikeNewCoins {
let backupPrv;

try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
4 changes: 2 additions & 2 deletions modules/abstract-substrate/src/abstractSubstrateCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export class SubstrateCoin extends BaseCoin {
// Decrypt private keys from KeyCard values
let userPrv;
try {
userPrv = this.bitgo.decrypt({
userPrv = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -311,7 +311,7 @@ export class SubstrateCoin extends BaseCoin {

let backupPrv;
try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
15 changes: 9 additions & 6 deletions modules/sdk-api/src/encryptV2.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { argon2id } from '@bitgo/argon2';
import { base64String, boundedInt, decodeWithCodec } from '@bitgo/sdk-core';
import { randomBytes } from 'crypto';
import { randomBytes, webcrypto } from 'crypto';
import * as t from 'io-ts';

/** Web Crypto subtle — browser global in DOM; Node/Electron main must use `webcrypto`. */
const subtle = globalThis.crypto?.subtle ?? webcrypto.subtle;

/** Default Argon2id parameters per RFC 9106 second recommendation
* @see https://www.rfc-editor.org/rfc/rfc9106#section-4
*/
Expand Down Expand Up @@ -80,7 +83,7 @@ async function argon2ToAesKey(
params: { memorySize: number; iterations: number; parallelism: number }
): Promise<CryptoKey> {
const keyBytes = await argon2Hash(password, salt, params);
return crypto.subtle.importKey('raw', keyBytes, { name: 'AES-GCM' }, false, ['encrypt', 'decrypt']);
return subtle.importKey('raw', keyBytes, { name: 'AES-GCM' }, false, ['encrypt', 'decrypt']);
}

export async function argon2ToHkdfKey(
Expand All @@ -89,11 +92,11 @@ export async function argon2ToHkdfKey(
params: { memorySize: number; iterations: number; parallelism: number }
): Promise<CryptoKey> {
const keyBytes = await argon2Hash(password, salt, params);
return crypto.subtle.importKey('raw', keyBytes, 'HKDF', false, ['deriveKey']);
return subtle.importKey('raw', keyBytes, 'HKDF', false, ['deriveKey']);
}

export function hkdfDeriveAesKey(hkdfKey: CryptoKey, hkdfSalt: Uint8Array, usage: KeyUsage): Promise<CryptoKey> {
return crypto.subtle.deriveKey(
return subtle.deriveKey(
{ name: 'HKDF', hash: 'SHA-256', salt: hkdfSalt, info: HKDF_INFO },
hkdfKey,
{ name: 'AES-GCM', length: 256 },
Expand All @@ -110,7 +113,7 @@ export async function aesGcmEncrypt(
): Promise<Uint8Array> {
const params: AesGcmParams = { name: 'AES-GCM', iv, tagLength: 128 };
if (additionalData) params.additionalData = additionalData;
const ct = await crypto.subtle.encrypt(params, key, new TextEncoder().encode(plaintext));
const ct = await subtle.encrypt(params, key, new TextEncoder().encode(plaintext));
return new Uint8Array(ct);
}

Expand All @@ -122,7 +125,7 @@ export async function aesGcmDecrypt(
): Promise<string> {
const params: AesGcmParams = { name: 'AES-GCM', iv, tagLength: 128 };
if (additionalData) params.additionalData = additionalData;
const plaintext = await crypto.subtle.decrypt(params, key, ct);
const plaintext = await subtle.decrypt(params, key, ct);
return new TextDecoder().decode(plaintext);
}

Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-ada/src/ada.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export class Ada extends BaseCoin {
// Decrypt private keys from KeyCard values
let userPrv;
try {
userPrv = this.bitgo.decrypt({
userPrv = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -476,7 +476,7 @@ export class Ada extends BaseCoin {

let backupPrv;
try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-algo/src/algo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,8 @@ export class Algo extends BaseCoin {
throw new Error('bitgo public key from the keyCard is required for non-bitgo recovery');
}
try {
userPrv = this.bitgo.decrypt({ input: params.userKey, password: params.walletPassphrase });
backupPrv = this.bitgo.decrypt({ input: params.backupKey, password: params.walletPassphrase });
userPrv = await this.bitgo.decryptAsync({ input: params.userKey, password: params.walletPassphrase });
backupPrv = await this.bitgo.decryptAsync({ input: params.backupKey, password: params.walletPassphrase });
const userKeyAddress = Utils.privateKeyToAlgoAddress(userPrv);
const backupKeyAddress = Utils.privateKeyToAlgoAddress(backupPrv);
txBuilder.numberOfRequiredSigners(2).setSigners([userKeyAddress, backupKeyAddress, params.bitgoKey]);
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-algo/test/unit/algo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ describe('ALGO:', function () {
},
{
message:
"unable to decrypt userKey or backupKey with the walletPassphrase provided, got error: password error - ccm: tag doesn't match",
'unable to decrypt userKey or backupKey with the walletPassphrase provided, got error: incorrect password',
}
);
});
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-avaxc/src/avaxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ export class AvaxC extends AbstractEthLikeNewCoins {
: new optionalDeps.ethUtil.BN(this.setGasPrice(params.gasPrice));
if (!userKey.startsWith('xpub') && !userKey.startsWith('xprv')) {
try {
userKey = this.bitgo.decrypt({
userKey = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -654,7 +654,7 @@ export class AvaxC extends AbstractEthLikeNewCoins {
let backupPrv;

try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-dot/src/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export class Dot extends BaseCoin {
// Decrypt private keys from KeyCard values
let userPrv;
try {
userPrv = this.bitgo.decrypt({
userPrv = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -422,7 +422,7 @@ export class Dot extends BaseCoin {

let backupPrv;
try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-etc/src/etc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class Etc extends AbstractEthLikeCoin {

if (!userKey.startsWith('xpub') && !userKey.startsWith('xprv')) {
try {
userKey = this.bitgo.decrypt({
userKey = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -108,7 +108,7 @@ export class Etc extends AbstractEthLikeCoin {
let backupPrv;

try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-eth/src/erc20Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class Erc20Token extends Eth {
let userPrv;
if (!userKey.startsWith('xpub') && !userKey.startsWith('xprv')) {
try {
userPrv = this.bitgo.decrypt({
userPrv = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -191,7 +191,7 @@ export class Erc20Token extends Eth {
let backupPrv;

try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-eth/src/erc721Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class Erc721Token extends Eth {
let userPrv;
if (!userKey.startsWith('xpub') && !userKey.startsWith('xprv')) {
try {
userPrv = this.bitgo.decrypt({
userPrv = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -191,7 +191,7 @@ export class Erc721Token extends Eth {
let backupPrv;

try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-eth/src/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class Eth extends AbstractEthLikeNewCoins {
: new optionalDeps.ethUtil.BN(this.setGasPrice(params.gasPrice));
if (!isUnsignedSweep) {
try {
userKey = this.bitgo.decrypt({
userKey = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -229,7 +229,7 @@ export class Eth extends AbstractEthLikeNewCoins {
let backupPrv;

try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
5 changes: 1 addition & 4 deletions modules/sdk-coin-ethlike/test/fixtures/ethlikeCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ export const ccr = {
},
};
export const encryptedUserKey =
'{"iv":"VFZ3jvXhxo1Z+Yaf2MtZnA==","v":1,"iter":10000,"ks":256,"ts":64,"mode"\n' +
':"ccm","adata":"","cipher":"aes","salt":"p+fkHuLa/8k=","ct":"hYG7pvljLIgCjZ\n' +
'53PBlCde5KZRmlUKKHLtDMk+HJfuU46hW+x+C9WsIAO4gFPnTCvFVmQ8x7czCtcNFub5AO2otOG\n' +
'OsX4GE2gXOEmCl1TpWwwNhm7yMUjGJUpgW6ZZgXSXdDitSKi4V/hk78SGSzjFOBSPYRa6I="}\n';
'{"iv":"VFZ3jvXhxo1Z+Yaf2MtZnA==","v":1,"iter":10000,"ks":256,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"p+fkHuLa/8k=","ct":"hYG7pvljLIgCjZ53PBlCde5KZRmlUKKHLtDMk+HJfuU46hW+x+C9WsIAO4gFPnTCvFVmQ8x7czCtcNFub5AO2otOGOsX4GE2gXOEmCl1TpWwwNhm7yMUjGJUpgW6ZZgXSXdDitSKi4V/hk78SGSzjFOBSPYRa6I="}';

export const custodialHot = {
hteth: {
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-hbar/src/hbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ export class Hbar extends BaseCoin {
let backUp: string | undefined;
if (!isUnsignedSweep) {
try {
userPrv = this.bitgo.decrypt({ input: params.userKey, password: params.walletPassphrase });
backUp = this.bitgo.decrypt({ input: params.backupKey, password: params.walletPassphrase });
userPrv = await this.bitgo.decryptAsync({ input: params.userKey, password: params.walletPassphrase });
backUp = await this.bitgo.decryptAsync({ input: params.backupKey, password: params.walletPassphrase });
} catch (e) {
throw new Error(
'unable to decrypt userKey or backupKey with the walletPassphrase provided, got error: ' + e.message
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-hbar/test/unit/hbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ describe('Hedera Hashgraph:', function () {
},
{
message:
"unable to decrypt userKey or backupKey with the walletPassphrase provided, got error: password error - ccm: tag doesn't match",
'unable to decrypt userKey or backupKey with the walletPassphrase provided, got error: incorrect password',
}
);
});
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-iota/src/iota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,15 +823,15 @@ export class Iota extends BaseCoin {
// Decrypt private keys from KeyCard values
let userPrv: string;
try {
userPrv = this.bitgo.decrypt({ input: userKey, password: params.walletPassphrase });
userPrv = await this.bitgo.decryptAsync({ input: userKey, password: params.walletPassphrase });
} catch (e) {
throw new Error(`Error decrypting user keychain: ${(e as Error).message}`);
}
const userSigningMaterial = JSON.parse(userPrv) as EDDSAMethodTypes.UserSigningMaterial;

let backupPrv: string;
try {
backupPrv = this.bitgo.decrypt({ input: backupKey, password: params.walletPassphrase });
backupPrv = await this.bitgo.decryptAsync({ input: backupKey, password: params.walletPassphrase });
} catch (e) {
throw new Error(`Error decrypting backup keychain: ${(e as Error).message}`);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-near/src/near.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export class Near extends BaseCoin {
// Decrypt private keys from KeyCard values
let userPrv;
try {
userPrv = this.bitgo.decrypt({
userPrv = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -666,7 +666,7 @@ export class Near extends BaseCoin {

let backupPrv;
try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-polyx/src/polyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class Polyx extends SubstrateCoin {
// Decrypt private keys from KeyCard values
let userPrv;
try {
userPrv = this.bitgo.decrypt({
userPrv = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -212,7 +212,7 @@ export class Polyx extends SubstrateCoin {

let backupPrv;
try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
8 changes: 4 additions & 4 deletions modules/sdk-coin-sol/src/sol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ export class Sol extends BaseCoin {
let userPrv;

try {
userPrv = this.bitgo.decrypt({
userPrv = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -1409,7 +1409,7 @@ export class Sol extends BaseCoin {

let backupPrv;
try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down Expand Up @@ -1718,7 +1718,7 @@ export class Sol extends BaseCoin {
let userPrv;

try {
userPrv = this.bitgo.decrypt({
userPrv = await this.bitgo.decryptAsync({
input: userKey,
password: params.walletPassphrase,
});
Expand All @@ -1730,7 +1730,7 @@ export class Sol extends BaseCoin {

let backupPrv;
try {
backupPrv = this.bitgo.decrypt({
backupPrv = await this.bitgo.decryptAsync({
input: backupKey,
password: params.walletPassphrase,
});
Expand Down
Loading
Loading