Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
replace generateMultiEd25519AccountFromPrivateKey with decodeMultiEd2…
…5519AccountPrivateKey
  • Loading branch information
wk3368 committed Dec 4, 2021
1 parent c0f6f68 commit 9984192
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/utils/account.ts
Expand Up @@ -80,9 +80,8 @@ export function showMultiEd25519Account(shard: MultiEd25519KeyShard): Record<str
};
}

export function generateMultiEd25519AccountFromPrivateKey(privateKey: string): MultiEd25519KeyShard {
export function decodeMultiEd25519AccountPrivateKey(privateKey: string): Record<string, any> {
const bytes = arrayify(privateKey)

const publicKeysLengthBytes = bytes.slice(0, 1);
const publicKeysLength = publicKeysLengthBytes[0];

Expand All @@ -101,15 +100,15 @@ export function generateMultiEd25519AccountFromPrivateKey(privateKey: string): M
for (let i = 0; i < publicKeysLength; i += 1) {
end = start + length
const publicKeyBytes = bytes.slice(start, end);
publicKeys.push(new Ed25519PublicKey(publicKeyBytes))
publicKeys.push(hexlify(publicKeyBytes))
start = end
}
for (let i = 0; i < privateKeysLength; i += 1) {
end = start + length
const privateKeyBytes = bytes.slice(start, end);
privateKeys.push(new Ed25519PrivateKey(privateKeyBytes))
privateKeys.push(hexlify(privateKeyBytes))
start = end
}
const shard = new MultiEd25519KeyShard(publicKeys, threshold, privateKeys)
return shard;

return { privateKeys, publicKeys, threshold };
}
9 changes: 7 additions & 2 deletions src/utils/multi-sign.spec.ts
Expand Up @@ -18,7 +18,7 @@ import {
} from "./tx";
import { createMultiEd25519KeyShard, signMultiEd25519KeyShard } from "./multi-sign";
import { dec2bin, bin2dec, setBit, isSetBit, dec2uint8array, uint8array2dec } from "./helper";
import { showMultiEd25519Account, generateMultiEd25519AccountFromPrivateKey } from "./account";
import { showMultiEd25519Account, decodeMultiEd25519AccountPrivateKey } from "./account";
import * as starcoin_types from "../lib/runtime/starcoin_types";

// Implemention of multi sign in https://starcoin.org/zh/developer/cli/multisig_account/
Expand Down Expand Up @@ -50,7 +50,12 @@ test('import from multiSign account privateKey', async () => {
const multiAccountAlice = showMultiEd25519Account(shardAlice)
console.log({ multiAccountAlice });

const shard = generateMultiEd25519AccountFromPrivateKey(multiAccountAlice.privateKey)
let shard
{
const { publicKeys, threshold, privateKeys } = decodeMultiEd25519AccountPrivateKey(multiAccountAlice.privateKey)
console.log('decodeMultiEd25519AccountPrivateKey', { publicKeys, threshold, privateKeys });
shard = await createMultiEd25519KeyShard(publicKeys, privateKeys, threshold)
}
const multiAccount = showMultiEd25519Account(shard)
console.log({ multiAccount });

Expand Down

0 comments on commit 9984192

Please sign in to comment.