Skip to content

Commit 560d944

Browse files
authored
feat: multisig support (#235)
* feat: add multisig types Signed-off-by: Norman <[email protected]> * fix: it's aliiiiveee Signed-off-by: Norman <[email protected]> * feat: wallet signTransaction opts Signed-off-by: Norman <[email protected]> * chore: revert pm changes Signed-off-by: Norman <[email protected]> * feat: expose helper function to work with CompactBitArray Signed-off-by: Norman <[email protected]> * chore: remove chainId signTransaction option Signed-off-by: Norman <[email protected]> * chore: revert artifact Signed-off-by: Norman <[email protected]> * chore: remove outdated comment Signed-off-by: Norman <[email protected]> --------- Signed-off-by: Norman <[email protected]>
1 parent 45cb8d2 commit 560d944

File tree

8 files changed

+580
-15
lines changed

8 files changed

+580
-15
lines changed

proto/tm2/multisig.proto

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
syntax = "proto3";
2+
package tm;
3+
4+
option go_package = "github.com/gnolang/gno/tm2/pkg/crypto/multisig/pb";
5+
6+
// imports
7+
import "google/protobuf/any.proto";
8+
9+
// messages
10+
message PubKeyMultisig {
11+
uint64 k = 1 [json_name = "threshold"];
12+
repeated google.protobuf.Any pub_keys = 2 [json_name = "pubkeys"];
13+
}
14+
15+
message Multisignature {
16+
CompactBitArray bit_array = 1;
17+
repeated bytes sigs = 2;
18+
}
19+
20+
message CompactBitArray {
21+
uint32 extra_bits_stored = 1 [json_name = "extra_bits"]; // The number of extra bits in elems.
22+
bytes elems = 2 [json_name = "bits"];
23+
}

src/proto/google/protobuf/any.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/proto/tm2/abci.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/proto/tm2/multisig.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { bytesToHex } from '@noble/hashes/utils';
2+
import { CompactBitArray } from './multisig';
3+
4+
describe('TestMarshalCompactBitArrayAmino', () => {
5+
const testCases = [
6+
{ marshalledBA: `null`, hexOutput: '' },
7+
{ marshalledBA: `null`, hexOutput: '' },
8+
{ marshalledBA: `"_"`, hexOutput: '0801120100' },
9+
{ marshalledBA: `"x"`, hexOutput: '0801120180' },
10+
{ marshalledBA: `"xx___"`, hexOutput: '08051201c0' },
11+
{ marshalledBA: `"xx______x"`, hexOutput: '08011202c080' },
12+
{ marshalledBA: `"xx_____________x"`, hexOutput: '1202c001' },
13+
];
14+
15+
test.each(testCases)('$marshalledBA', async ({ marshalledBA, hexOutput }) => {
16+
// Parse JSON into CompactBitArray
17+
const jsonData = JSON.parse(marshalledBA);
18+
const bA = CompactBitArray.fromJSON(jsonData);
19+
20+
// Marshal using Amino
21+
const bz = CompactBitArray.encode(bA).finish();
22+
23+
// Convert bytes to hex and compare
24+
const actualHex = bytesToHex(bz);
25+
expect(actualHex).toBe(hexOutput);
26+
});
27+
});

0 commit comments

Comments
 (0)