Skip to content

Commit 4840c7e

Browse files
authored
Merge pull request #86 from virtualeconomy/develop
release: v0.2.4
2 parents 65448d6 + 69c163f commit 4840c7e

File tree

14 files changed

+681
-15
lines changed

14 files changed

+681
-15
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/dist
22
/lib
33
/node_modules
4-
*.env
4+
*.env
5+
test*.js

package-lock.json

Lines changed: 31 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@virtualeconomy/js-vsys",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "The official JavaScript SDK for VSYS APIs",
55
"keywords": [
66
"vsys",
@@ -24,10 +24,12 @@
2424
"axlsign": "^1.0.0",
2525
"bignumber.js": "^9.0.2",
2626
"blakejs": "^1.1.1",
27+
"bn.js": "^5.2.1",
2728
"bs58": "^5.0.0",
2829
"buffer": "^6.0.3",
2930
"crypto-js": "^4.1.1",
3031
"js-sha256": "^0.9.0",
32+
"js-sha512": "^0.8.0",
3133
"keccak256": "^1.0.6",
3234
"node-fetch": "^2.6.0"
3335
},

spec/multisign_spec.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* multisign_spec tests module multisign
3+
* @module multiSignSpec
4+
*/
5+
6+
'use strict';
7+
8+
import { Buffer } from 'buffer';
9+
import Axlsign from 'axlsign';
10+
import bs58 from 'bs58';
11+
import * as jv from '../src/index.js';
12+
13+
const PRI_KEY_1 = 'EV9ADJzYKZpk4MjxEkXxDSfRRSzBFnA9LEQNbepKZRFc';
14+
const PRI_KEY_2 = '3hQRGJkqKFbks77cZ12ugHxDtbweH3EZjhfVzfr4RqPs';
15+
16+
const MSG = Buffer.from('test');
17+
const RAND = Buffer.from('b298c9d1947fcb8373a200232b6f6c79f7854814c74e66613b2ea0c843bdad50cb3c8373942f0a8a0aaada8c238c011279554f7459bab560b6eb43992aaf3886', 'hex');
18+
19+
const MULPK1 = new jv.MultiSignPriKey(Buffer.from(bs58.decode(PRI_KEY_1)));
20+
const MULPK2 = new jv.MultiSignPriKey(Buffer.from(bs58.decode(PRI_KEY_2)));
21+
22+
describe('Test multisign', function() {
23+
it('should work with one key', () => {
24+
const A = MULPK1.A;
25+
const allAs = [A];
26+
27+
const xA = MULPK1.getxA([A]);
28+
const xAs = [xA];
29+
const unionA = jv.MultiSign.getUnionA(xAs);
30+
31+
const R = MULPK1.getR(MSG, RAND);
32+
const Rs = [R];
33+
const unionR = jv.MultiSign.getUnionR(Rs);
34+
35+
const subSig = MULPK1.sign(MSG, RAND, unionA, unionR, allAs);
36+
const mulSig = jv.MultiSign.getSig(unionA, unionR, [subSig]);
37+
38+
const bpA = MULPK1.getbpA(allAs);
39+
const bpAs = [bpA];
40+
const mulPub = jv.MultiSign.getPub(bpAs);
41+
42+
const rawSig = Buffer.from(Axlsign.sign(MULPK1.priKey, MSG, RAND));
43+
44+
expect(rawSig.equals(mulSig)).toBeTrue();
45+
46+
const rawPub = Buffer.from(Axlsign.derivePublicKey(MULPK1.priKey));
47+
expect(rawPub.equals(mulPub)).toBeTrue();
48+
49+
const valid = Axlsign.verify(mulPub, MSG, mulSig);
50+
expect(valid).toBeTrue();
51+
});
52+
53+
it('should work with two keys', () => {
54+
const A1 = MULPK1.A;
55+
const A2 = MULPK2.A;
56+
57+
const allAs = [A1, A2];
58+
59+
const xA1 = MULPK1.getxA(allAs);
60+
const xA2 = MULPK2.getxA(allAs);
61+
const xAs = [xA1, xA2];
62+
const unionA = jv.MultiSign.getUnionA(xAs);
63+
64+
const R1 = MULPK1.getR(MSG, RAND);
65+
const R2 = MULPK2.getR(MSG, RAND);
66+
const Rs = [R1, R2];
67+
const unionR = jv.MultiSign.getUnionR(Rs);
68+
69+
const subSig1 = MULPK1.sign(MSG, RAND, unionA, unionR, allAs);
70+
const subSig2 = MULPK2.sign(MSG, RAND, unionA, unionR, allAs);
71+
const sigs = [subSig1, subSig2];
72+
const mulSig = jv.MultiSign.getSig(unionA, unionR, sigs);
73+
74+
const bpA1 = MULPK1.getbpA(allAs);
75+
const bpA2 = MULPK2.getbpA(allAs);
76+
const bpAs = [bpA1, bpA2];
77+
const mulPub = jv.MultiSign.getPub(bpAs);
78+
79+
const valid = Axlsign.verify(mulPub, MSG, mulSig);
80+
expect(valid).toBeTrue();
81+
});
82+
});

src/contract/tok_ctrt_factory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as nft_ctrt_v2 from './nft_ctrt_v2.js';
1616
import * as sys_ctrt from './sys_ctrt.js';
1717

1818
/** TokCtrtType is the class for token contract types */
19-
class TokCtrtType extends en.Enum {
19+
export class TokCtrtType extends en.Enum {
2020
static elems = {
2121
NFT: 'NonFungibleContract',
2222
NFT_V2_BLACKLIST: 'NFTContractWithBlacklist',

src/data_entry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Long extends DataEntry {
145145
* @returns {Long} The data entry.
146146
*/
147147
static fromBytes(b) {
148-
return new this(new md.Long.fromNumber(bp.unpackUInt64(b)));
148+
return new this(md.Long.fromNumber(bp.unpackUInt64(b)));
149149
}
150150

151151
/**

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './account.js';
44
export * from './tx_req.js';
55
export * from './model.js';
66
export * as de from './data_entry.js';
7+
export * from './multisign.js';
78
export * from './contract/ctrt.js';
89
export * from './contract/lock_ctrt.js';
910
export * from './contract/atomic_swap_ctrt.js';

src/model.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,12 +724,22 @@ export class TokenID extends FixedSizedB58Str {
724724
return this.data === this.constructor.TESTNET_VSYS_TOK_ID;
725725
}
726726

727+
/**
728+
* tokIdx returns the token index from the token id.
729+
* @returns {TokenIdx} The token index.
730+
*/
731+
get tokIdx() {
732+
const tokIdNoChecksum = this.bytes.slice(0, -4);
733+
const tokIdxBytes = tokIdNoChecksum.slice(-4);
734+
return new TokenIdx(bp.unpackUInt32(tokIdxBytes));
735+
}
736+
727737
/**
728738
* getCtrtId gets the contract ID of the given token ID.
729739
* @returns {CtrtID} The contract ID.
730740
*/
731741
getCtrtId() {
732-
const b = bs58.decode(this.data);
742+
const b = this.bytes;
733743
const rawCtrtId = b.slice(
734744
1,
735745
b.length - CtrtMeta.TOKEN_IDX_BYTES_LEN - CtrtMeta.CHECKSUM_LEN

0 commit comments

Comments
 (0)