Sort who on multisig (#312)

This commit is contained in:
Jaco Greeff
2020-04-24 19:50:09 +02:00
committed by GitHub
parent c32343671a
commit dd55faec48
9 changed files with 75 additions and 38 deletions
+3 -3
View File
@@ -26,9 +26,9 @@
"store": "^2.0.12"
},
"devDependencies": {
"@polkadot/keyring": "^2.9.0-beta.0",
"@polkadot/types": "^1.12.0-beta.5",
"@polkadot/util": "^2.9.0-beta.0",
"@polkadot/keyring": "^2.9.0-beta.1",
"@polkadot/types": "^1.12.0-beta.6",
"@polkadot/util": "^2.9.0-beta.1",
"@types/ledgerhq__hw-transport-node-hid": "^4.22.1",
"@types/ledgerhq__hw-transport-u2f": "^4.21.1",
"@types/mkdirp": "^1.0.0",
+4 -2
View File
@@ -10,7 +10,7 @@ import { CreateResult, KeyringAddress, KeyringAddressType, KeyringItemType, Keyr
import BN from 'bn.js';
import createPair from '@polkadot/keyring/pair';
import chains from '@polkadot/ui-settings/defaults/chains';
import { bnToBn, hexToU8a, isHex, isString } from '@polkadot/util';
import { bnToBn, hexToU8a, isHex, isString, u8aSorted } from '@polkadot/util';
import { createKeyMulti } from '@polkadot/util-crypto';
import env from './observable/development';
@@ -45,7 +45,9 @@ export class Keyring extends Base implements KeyringStruct {
public addMultisig (addresses: (string | Uint8Array)[], threshold: BigInt | BN | number, meta: KeyringPair$Meta = {}): CreateResult {
const address = createKeyMulti(addresses, threshold);
const who = addresses.map((who) => this.encodeAddress(who));
// we could use `sortAddresses`, but rather use internal encode/decode so we are 100%
const who = u8aSorted(addresses.map((who) => this.decodeAddress(who))).map((who) => this.encodeAddress(who));
return this.addExternal(address, { ...meta, isMultisig: true, threshold: bnToBn(threshold).toNumber(), who });
}