Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MultiEd25519PublicKey.deserialize is work
  • Loading branch information
wk3368 committed Oct 28, 2021
1 parent 99db3e6 commit cfc9802
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib/runtime/starcoin_types/index.ts
Expand Up @@ -490,12 +490,15 @@ export class MultiEd25519PublicKey {
}

static deserialize(deserializer: Deserializer): MultiEd25519PublicKey {
const length = deserializer.deserializeLen();
const bytes = deserializer.deserializeBytes()
const public_keys: Seq<Ed25519PublicKey> = [];
for (let i = 0; i < length; i++) {
public_keys.push(Ed25519PublicKey.deserialize(deserializer));
const count = (bytes.length - 1) / 32
for (let i = 0; i < count; i++) {
const start = i * 32;
const end = start + 32;
public_keys.push(new Ed25519PublicKey(bytes.slice(start, end)));
}
const threshold = deserializer.deserializeU8();
const threshold = new DataView(bytes.slice(-1).buffer, 0).getUint8(0);;
return new MultiEd25519PublicKey(public_keys, threshold);
}

Expand Down
5 changes: 5 additions & 0 deletions src/utils/multi-sign.spec.ts
Expand Up @@ -154,6 +154,11 @@ test('2-3 multi sign', async () => {
// const rtx = bcsDecode(starcoin_types.RawUserTransaction, hex)
// console.log({ rtx })

const hex = '0x61547c6a1ef36e9e99865ce7ac028ee79aff404d279b568272bc7154802d4856bbc95ddc2b2926d1a451ea68fa74274aa04af97d8e2aefccb297e6ef61992d42e8e8cdd5b17a37fe7e8fe446d067e7a9907cf7783aca204ccb623972176614c0a002'
const multiEd25519PublicKey = bcsDecode(starcoin_types.MultiEd25519PublicKey, hex)
console.log({ multiEd25519PublicKey })
console.log(bcsEncode(multiEd25519PublicKey as starcoin_types.MultiEd25519PublicKey))
expect(hex).toEqual(bcsEncode(multiEd25519PublicKey as starcoin_types.MultiEd25519PublicKey));

const signatureAlice = await getSignatureHex(rawUserTransaction, alice.private_key)
console.log({ signatureAlice })
Expand Down

0 comments on commit cfc9802

Please sign in to comment.