Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MultiEd25519Signature.bitmap should be Uint8array in binary
  • Loading branch information
wk3368 committed Oct 27, 2021
1 parent bdf7905 commit 539d58c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/lib/runtime/starcoin_types/index.ts
Expand Up @@ -4,7 +4,7 @@ import { BcsDeserializer, BcsSerializer } from '../bcs';
import { Serializer } from '../serde/serializer';
import { Deserializer } from '../serde/deserializer';
import { Optional, Seq, Tuple, ListTuple, unit, bool, int8, int16, int32, int64, int128, uint8, uint16, uint32, uint64, uint128, float32, float64, char, str, bytes } from '../serde/types';
import { dec2bin, bin2dec, setBit, isSetBit } from "../../../utils/helper";
import { dec2bin, bin2dec, setBit, isSetBit, dec2uint8array, uint8array2dec } from "../../../utils/helper";

const CryptoMaterialError = {
SerializationError: 'Struct to be signed does not serialize correctly',
Expand Down Expand Up @@ -551,7 +551,7 @@ export class MultiEd25519Signature {
this.signatures.forEach((signature) => {
signature.serialize(serializer)
})
serializer.serializeU8(this.bitmap);
serializer.serializeBytes(dec2uint8array(this.bitmap));
}

static deserialize(deserializer: Deserializer): MultiEd25519Signature {
Expand All @@ -560,7 +560,7 @@ export class MultiEd25519Signature {
for (let i = 0; i < length; i++) {
signatures.push(Ed25519Signature.deserialize(deserializer));
}
const bitmap = deserializer.deserializeU8();
const bitmap = uint8array2dec(deserializer.deserializeBytes());
return new MultiEd25519Signature(signatures, bitmap);
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/multi-sign.spec.ts
Expand Up @@ -102,12 +102,12 @@ test('2-3 multi sign', async () => {
const hex = '0xbc317a9becacae3e6ddf3c8a9c2efd64000000000000000002000000000000000000000000000000010f5472616e73666572536372697074730f706565725f746f5f706565725f76320107000000000000000000000000000000010353544303535443000210d7f20befd34b9f1ab8aeae98b82a5a511080969800000000000000000000000000809698000000000001000000000000000d3078313a3a5354433a3a5354432e3c6f6100000000fb'
const rtx = bcsDecode(starcoin_types.RawUserTransaction, hex)
console.log({ rtx })
const signatures = await signMultiEd25519KeyShard(shardBob, rtx)
const signatures = await signMultiEd25519KeyShard(shardTom, rtx)
console.log({ signatures })

// write Uint8Array into local binary file, and read form it
try {
writeFileSync("binaryfile", arrayify(multiAccountBob.privateKey));
writeFileSync("binaryfile", arrayify(multiAccountTom.privateKey));
const rbuf = readFileSync("binaryfile");
console.log({ rbuf });
console.log(hexlify(rbuf));
Expand Down
2 changes: 1 addition & 1 deletion src/utils/multi-sign.ts
Expand Up @@ -92,5 +92,5 @@ export async function signMultiEd25519KeyShard(multiEd25519KeyShard: MultiEd2551
console.log({ signatures })
const multiEd25519Signature = MultiEd25519Signature.build(signatures)
console.log({ multiEd25519Signature })
return new MultiEd25519SignatureShard(multiEd25519Signature, this.threshold)
return new MultiEd25519SignatureShard(multiEd25519Signature, multiEd25519KeyShard.threshold)
}

0 comments on commit 539d58c

Please sign in to comment.