From cb37451f8f5fd7bc81758eb9695e4f68b833a83e Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 22 Mar 2021 16:46:10 +0100 Subject: [PATCH] Add multisig address derivation example --- packages/cli/examples/multisig_address.ts | 31 +++++++++++++++++++++++ packages/cli/package.json | 1 + packages/cli/run_examples.sh | 1 + 3 files changed, 33 insertions(+) create mode 100644 packages/cli/examples/multisig_address.ts diff --git a/packages/cli/examples/multisig_address.ts b/packages/cli/examples/multisig_address.ts new file mode 100644 index 00000000..8e754d2e --- /dev/null +++ b/packages/cli/examples/multisig_address.ts @@ -0,0 +1,31 @@ +import { MultisigThresholdPubkey, pubkeyToRawAddress } from "@cosmjs/amino"; +import { Bech32 } from "@cosmjs/encoding"; + +// https://github.com/cosmos/cosmjs/issues/673#issuecomment-779847238 +const multisigPubkey: MultisigThresholdPubkey = { + "type": "tendermint/PubKeyMultisigThreshold", + "value": { + "threshold": "3", + "pubkeys": [ + { + "type": "tendermint/PubKeySecp256k1", + "value": "A4KZH7VSRwW/6RTExROivRYKsQP63LnGcBlXFo+eKGpQ" + }, + { + "type": "tendermint/PubKeySecp256k1", + "value": "A8/Cq4VigOnDgl6RSdcx97fjrdCo/qwAX6C34n7ZDZLs" + }, + { + "type": "tendermint/PubKeySecp256k1", + "value": "ApKgZuwy03xgdRnXqG6yEHATomsWDOPacy7nbpsuUCSS" + }, + { + "type": "tendermint/PubKeySecp256k1", + "value": "Aptm8E3WSSFS0RTAIUW+bLi/slYnTEE+h4qPTG28CHfq" + } + ] + } +}; + +const address = Bech32.encode("cosmos", pubkeyToRawAddress(multisigPubkey)); +console.log(address); diff --git a/packages/cli/package.json b/packages/cli/package.json index 5949e477..7405f013 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -39,6 +39,7 @@ "!**/testdata/" ], "dependencies": { + "@cosmjs/amino": "^0.25.0-alpha.0", "@cosmjs/cosmwasm-launchpad": "^0.25.0-alpha.0", "@cosmjs/cosmwasm-stargate": "^0.25.0-alpha.0", "@cosmjs/crypto": "^0.25.0-alpha.0", diff --git a/packages/cli/run_examples.sh b/packages/cli/run_examples.sh index fde36611..8ec0e10e 100755 --- a/packages/cli/run_examples.sh +++ b/packages/cli/run_examples.sh @@ -13,6 +13,7 @@ cosmwasm-cli --init examples/generate_address.ts --code "process.exit(0)" cosmwasm-cli --init examples/helpers.ts --code "process.exit(0)" cosmwasm-cli --init examples/local_faucet.ts --code "process.exit(0)" cosmwasm-cli --init examples/mask.ts --code "process.exit(0)" +cosmwasm-cli --init examples/multisig_address.ts --code "process.exit(0)" if [ -n "${SIMAPP_ENABLED:-}" ]; then cosmwasm-cli --init examples/stargate.ts --code "process.exit(0)" fi