Skip to content
Merged
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
16 changes: 8 additions & 8 deletions modules/sdk-coin-dot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
"@bitgo/sdk-lib-mpc": "^10.17.0",
"@bitgo/statics": "^59.8.0",
"@bitgo/wasm-dot": "^1.7.0",
"@polkadot/api": "14.1.1",
"@polkadot/api-augment": "14.1.1",
"@polkadot/keyring": "13.5.6",
"@polkadot/types": "14.1.1",
"@polkadot/util": "13.5.6",
"@polkadot/util-crypto": "13.5.6",
"@substrate/txwrapper-core": "7.5.2",
"@substrate/txwrapper-polkadot": "7.5.2",
"@polkadot/api": "16.5.6",
"@polkadot/api-augment": "16.5.6",
"@polkadot/keyring": "14.0.3",
"@polkadot/types": "16.5.6",
"@polkadot/util": "14.0.3",
"@polkadot/util-crypto": "14.0.3",
"@substrate/txwrapper-core": "7.5.3",
"@substrate/txwrapper-polkadot": "7.5.3",
"bignumber.js": "^9.0.0",
"bs58": "^4.0.1",
"hi-base32": "^0.5.1",
Expand Down
23 changes: 21 additions & 2 deletions modules/sdk-coin-dot/src/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ export interface VerifiedTransactionParameters {

const dotUtils = Utils.default;

function isEddsaSigningMaterial(value: unknown): value is EddsaSigningMaterial {
if (typeof value !== 'object' || value === null) {
return false;
}
if (!('version' in value)) {
return false;
}
if (value.version === 'v1') {
return 'userPrv' in value && typeof value.userPrv === 'string';
}
if (value.version === 'v2') {
return 'encryptedUserKey' in value && typeof value.encryptedUserKey === 'string';
}
return false;
}

export class Dot extends BaseCoin {
protected readonly _staticsCoin: Readonly<StaticsBaseCoin>;
readonly MAX_VALIDITY_DURATION = 2400;
Expand Down Expand Up @@ -348,6 +364,8 @@ export class Dot extends BaseCoin {
* Builds a funds recovery transaction without BitGo
* @param {MPCRecoveryOptions} params parameters needed to construct and
* (maybe) sign the transaction
* @param {EddsaSigningMaterial} [precomputedMaterial] optional decrypted
* material from recoverConsolidations; non-matching values are ignored
*
* @returns {MPCTx} the serialized transaction hex string and index
* of the address being swept
Expand Down Expand Up @@ -402,8 +420,9 @@ export class Dot extends BaseCoin {
assert(params.backupKey, 'missing backupKey');
assert(params.walletPassphrase, 'missing wallet passphrase');

const signingMaterial =
precomputedMaterial ?? (await this.getEddsaSigningMaterial(params.userKey, params.walletPassphrase));
const signingMaterial = isEddsaSigningMaterial(precomputedMaterial)
? precomputedMaterial
: await this.getEddsaSigningMaterial(params.userKey, params.walletPassphrase);
await this.addRecoverySignature(
signingMaterial,
params.backupKey.replace(/\s/g, ''),
Expand Down
38 changes: 37 additions & 1 deletion modules/sdk-coin-dot/test/unit/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { EDDSAMethods, MPCTx, MPCTxs, TransactionType, Wallet } from '@bitgo/sdk
import { coins } from '@bitgo/statics';
import { buildTransaction, type BuildContext, type Material } from '@bitgo/wasm-dot';
import { MPSUtil } from '@bitgo/sdk-lib-mpc';
import { EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/v4/Extrinsic';
import utils from '../../src/lib/utils';
import { explainDotTransaction } from '../../src/lib';
import { explainDotTransaction, SingletonRegistry } from '../../src/lib';

describe('DOT:', function () {
let bitgo: TestBitGoAPI;
Expand Down Expand Up @@ -436,6 +437,19 @@ describe('DOT:', function () {
should.deepEqual(txJson.transactionVersion, txVersion);
should.deepEqual(txJson.chainName, chainName);
should.deepEqual(txJson.eraPeriod, basecoin.SWEEP_TXN_DURATION);

const extras = SingletonRegistry.getInstance(utils.getMaterial(coins.get('tdot')))
.createType('ExtrinsicPayload', res.txRequests[0].transactions[0].unsignedTx.serializedTx, {
version: EXTRINSIC_VERSION,
})
.toJSON() as { tip?: string | number; assetId?: unknown; mode?: number | string };
should.equal(Number(extras.tip ?? 0), 0);
should.equal(Number(extras.mode ?? 0), 0);
should.equal(
extras.assetId === null || extras.assetId === undefined,
true,
`expected ChargeAsset assetId None, got ${JSON.stringify(extras.assetId)}`
);
});
});

Expand Down Expand Up @@ -600,6 +614,28 @@ describe('DOT:', function () {
res.should.not.be.empty();
sandBox.assert.calledOnce(getEddsaMaterialSpy);
});

it('should ignore a non-signing-material second arg (WRW openSSL WASM buffer)', async function () {
const getEddsaMaterialSpy = sandBox.spy(
basecoin as unknown as { getEddsaSigningMaterial: unknown },
'getEddsaSigningMaterial'
);

const res = (await basecoin.recover(
{
userKey: mpcV2UserKey,
backupKey: mpcV2BackupKey,
bitgoKey: mpcV2CommonKeyChain,
walletPassphrase,
recoveryDestination: destAddr,
},
new ArrayBuffer(8)
)) as MPCTx;

res.should.not.be.empty();
res.should.hasOwnProperty('serializedTx');
sandBox.assert.calledOnce(getEddsaMaterialSpy);
});
});

describe('Build Consolidation Recoveries:', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import assert from 'assert';
import should from 'should';
import sinon from 'sinon';
import { TransferBuilder } from '../../../src/lib';
import { EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/v4/Extrinsic';
import { SingletonRegistry, TransferBuilder } from '../../../src/lib';
import { ProxyType } from '../../../src/lib/iface';
import utils from '../../../src/lib/utils';
import { accounts, rawTx, chainName, txVersion, genesisHash, specVersion, mockTssSignature } from '../../resources';
Expand Down Expand Up @@ -409,6 +410,17 @@ describe('Dot Transfer Builder', () => {
should.deepEqual(txJson.chainName, chainName);
should.deepEqual(txJson.eraPeriod, 64);

const extras = SingletonRegistry.getInstance(utils.getMaterial(buildTestConfig()))
.createType('ExtrinsicPayload', tx.toBroadcastFormat(), { version: EXTRINSIC_VERSION })
.toJSON() as { tip?: string | number; assetId?: unknown; mode?: number | string };
should.equal(Number(extras.tip ?? 0), 0);
should.equal(Number(extras.mode ?? 0), 0);
should.equal(
extras.assetId === null || extras.assetId === undefined,
true,
`expected ChargeAsset assetId None, got ${JSON.stringify(extras.assetId)}`
);

const inputs = tx.inputs[0];
should.deepEqual(inputs.address, sender.address);
should.deepEqual(inputs.value, consolidationValue);
Expand Down
26 changes: 18 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@
"secp256k1": "5.0.1",
"socks": "2.8.9",
"web3-utils": "4.2.1",
"@polkadot/api": "14.1.1",
"@polkadot/util": "13.5.6",
"@polkadot/util-crypto": "13.5.6",
"@polkadot/keyring": "13.5.6",
"@polkadot/api": "16.5.6",
"@polkadot/api-augment": "16.5.6",
"@polkadot/types": "16.5.6",
"@polkadot/keyring": "14.0.3",
"@polkadot/util": "14.0.3",
"@polkadot/util-crypto": "14.0.3",
"@polkadot/x-randomvalues": "14.0.3",
"@substrate/txwrapper-core": "7.5.3",
"@substrate/txwrapper-polkadot": "7.5.3",
"elliptic": "^6.6.1",
"cookie": "^0.7.1",
"axios": "1.18.0",
Expand Down Expand Up @@ -187,10 +192,15 @@
"secp256k1": "5.0.1",
"socks": "2.8.9",
"web3-utils": "4.2.1",
"@polkadot/api": "14.1.1",
"@polkadot/util": "13.5.6",
"@polkadot/util-crypto": "13.5.6",
"@polkadot/keyring": "13.5.6",
"@polkadot/api": "16.5.6",
"@polkadot/api-augment": "16.5.6",
"@polkadot/types": "16.5.6",
"@polkadot/keyring": "14.0.3",
"@polkadot/util": "14.0.3",
"@polkadot/util-crypto": "14.0.3",
"@polkadot/x-randomvalues": "14.0.3",
"@substrate/txwrapper-core": "7.5.3",
"@substrate/txwrapper-polkadot": "7.5.3",
"elliptic": "^6.6.1",
"cookie": "^0.7.1",
"axios": "1.18.0",
Expand Down
Loading
Loading