Created
March 10, 2020 12:37
-
-
Save dgarcia360/adbf0277d1540e4084d0588288810590 to your computer and use it in GitHub Desktop.
Create 1-of-1 multisig when cosigner private keys are known
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Account, | |
AggregateTransaction, | |
Deadline, | |
MultisigAccountModificationTransaction, | |
NetworkType, | |
RepositoryFactoryHttp, | |
UInt64, | |
} from 'symbol-sdk'; | |
/* start block 01 */ | |
// replace with network type | |
const networkType = NetworkType.TEST_NET; | |
// replace with candidate multisig private key | |
const multisigPrivateKey = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; | |
const multisigAccount = Account.createFromPrivateKey(multisigPrivateKey, networkType); | |
// replace with cosignatory 1 public key | |
const cosignatory1PrivateKey = 'E59EF184A612D4C3C4D89B5950EB57262C69862B2F96E59C5043BF41765C482F'; | |
const cosignatory1Account = Account.createFromPrivateKey(cosignatory1PrivateKey, networkType); | |
/* end block 01 */ | |
/* start block 02 */ | |
const multisigAccountModificationTransaction = MultisigAccountModificationTransaction.create( | |
Deadline.create(), | |
1, | |
1, | |
[cosignatory1Account.publicAccount], | |
[], | |
networkType); | |
/* end block 02 */ | |
/* start block 03 */ | |
const aggregateTransaction = AggregateTransaction.createComplete( | |
Deadline.create(), | |
[multisigAccountModificationTransaction.toAggregate(multisigAccount.publicAccount)], | |
networkType, | |
[], | |
UInt64.fromUint(2000000)); | |
/* end block 03 */ | |
/* start block 04 */ | |
// replace with meta.generationHash (nodeUrl + '/block/1') | |
const networkGenerationHash = '44D2225B8932C9A96DCB13508CBCDFFA9A9663BFBA2354FEEC8FCFCB7E19846C'; | |
const signedTransaction = multisigAccount.signTransactionWithCosignatories(aggregateTransaction, [cosignatory1Account], networkGenerationHash); | |
console.log(signedTransaction.hash); | |
/* end block 04 */ | |
/* start block 05 */ | |
// replace with node endpoint | |
const nodeUrl = 'http://api-01.us-west-1.symboldev.network:3000'; | |
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl); | |
const transactionHttp = repositoryFactory.createTransactionRepository(); | |
transactionHttp | |
.announce(signedTransaction) | |
.subscribe( | |
(x) => console.log(x), | |
(err) => console.log(err)); | |
/* end block 05 */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment