-
Notifications
You must be signed in to change notification settings - Fork 5
/
calculateMultisigAddress.ts
28 lines (24 loc) · 1.04 KB
/
calculateMultisigAddress.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { encodeAddress, decodeAddress, createKeyMulti } from '@polkadot/util-crypto';
import { u8aToHex } from '@polkadot/util';
import yargs from 'yargs';
const args = yargs
.options({
addresses: { type: 'array', demandOption: true, alias: 'a', coerce: JSON.parse },
threshold: { type: 'number', demandOption: true, alias: 't' },
})
.check((argv) => {
// Check length
console.log(argv.addresses.length);
if (argv.addresses.length < 2) {
throw new Error('Addresses array must have at least a length of 2');
}
// Ensure that addresses array is correct
for (const i of argv['addresses']) {
if (typeof i !== 'string' || decodeAddress(i).length != 32)
throw new Error(`${i} is not a valid address. Please enter a valid array of addresses`);
return true;
}
}).argv;
const multisigAddress = u8aToHex(createKeyMulti(args['addresses'], BigInt(args['threshold'])));
console.log(`32 Bytes Multisig Address: ${multisigAddress}`);
console.log(`Encoded (Generic): ${encodeAddress(multisigAddress)}`);