Skip to content

Commit 907badc

Browse files
authored
Merge pull request #75 from hypersign-protocol/issues#74
test case using chai and mocha
2 parents 2bf71c7 + a5244f8 commit 907badc

File tree

9 files changed

+1862
-96
lines changed

9 files changed

+1862
-96
lines changed

package.json

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
11
{
2-
"name": "hs-ssi-sdk",
3-
"version": "6.2.0",
4-
"description": "sdk is an implementation of proposed DID by W3C",
5-
"main": "build/src/index.js",
6-
"scripts": {
7-
"test": "cd test/ssi && node did.js && node private-did.js && node schema.js && cd credentials && node test1.js && node test2.js && node updateCredStatus.js",
8-
"start": "node build/index.js",
9-
"build": "npm run lint:fix && npm run prettier && rimraf build && tsc -p .",
10-
"prettier": "prettier --config .prettierrc.json --write src/**/*.ts",
11-
"prepublish": "npm run build",
12-
"lint": "eslint . --ext .ts",
13-
"lint:fix": "npm run lint -- --fix",
14-
"prepare": "husky install"
15-
},
16-
"author": "Hypersign Team",
17-
"license": "ISC",
18-
"dependencies": {
19-
"@cosmjs/proto-signing": "^0.27.0",
20-
"@cosmjs/stargate": "^0.27.0",
21-
"@digitalbazaar/ed25519-signature-2020": "^3.0.0",
22-
"@digitalbazaar/ed25519-verification-key-2018": "^3.1.2",
23-
"@digitalbazaar/ed25519-verification-key-2020": "^3.3.0",
24-
"@stablelib/ed25519": "^1.0.2",
25-
"axios": "^0.19.0",
26-
"crypto-ld": "^6.0.0",
27-
"jsonld": "^3.1.1",
28-
"jsonld-signatures": "^9.0.0",
29-
"node-fetch": "^2.6.1",
30-
"protobufjs": "^6.11.2",
31-
"uuid": "^8.3.0",
32-
"vc-js": "https://github.com/hypersign-protocol/vc-js"
33-
},
34-
"devDependencies": {
35-
"@types/jest": "^27.5.1",
36-
"@types/node": "^14.11.2",
37-
"@typescript-eslint/eslint-plugin": "^5.4.0",
38-
"@typescript-eslint/parser": "^5.4.0",
39-
"eslint": "^7.32.0",
40-
"husky": "^7.0.4",
41-
"jest": "^28.1.0",
42-
"prettier": "^2.4.1",
43-
"rimraf": "^3.0.2",
44-
"ts-jest": "^28.0.3",
45-
"typescript": "^4.5.5"
46-
}
47-
}
2+
"name": "hs-ssi-sdk",
3+
"version": "6.2.0",
4+
"description": "sdk is an implementation of proposed DID by W3C",
5+
"main": "build/src/index.js",
6+
"scripts": {
7+
"test": "cd test/ssi && node did.js && node private-did.js && node schema.js && cd credentials && node test1.js && node test2.js",
8+
"test_chai": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'src/tests/*.ts' --exit --timeout 40000",
9+
"start": "node build/index.js",
10+
"build": "npm run lint:fix && npm run prettier && rimraf build && tsc -p .",
11+
"prettier": "prettier --config .prettierrc.json --write src/**/*.ts",
12+
"prepublish": "npm run build",
13+
"lint": "eslint . --ext .ts",
14+
"lint:fix": "npm run lint -- --fix",
15+
"prepare": "husky install"
16+
},
17+
"author": "Hypersign Team",
18+
"license": "ISC",
19+
"dependencies": {
20+
"@cosmjs/proto-signing": "^0.27.0",
21+
"@cosmjs/stargate": "^0.27.0",
22+
"@digitalbazaar/ed25519-signature-2020": "^3.0.0",
23+
"@digitalbazaar/ed25519-verification-key-2018": "^3.1.2",
24+
"@digitalbazaar/ed25519-verification-key-2020": "^3.3.0",
25+
"@stablelib/ed25519": "^1.0.2",
26+
"axios": "^0.19.0",
27+
"crypto-ld": "^6.0.0",
28+
"jsonld": "^3.1.1",
29+
"jsonld-signatures": "^9.0.0",
30+
"node-fetch": "^2.6.1",
31+
"protobufjs": "^6.11.2",
32+
"uuid": "^8.3.0",
33+
"vc-js": "https://github.com/hypersign-protocol/vc-js"
34+
},
35+
"devDependencies": {
36+
"@types/chai": "^4.3.4",
37+
"@types/mocha": "^10.0.1",
38+
"@types/node": "^14.11.2",
39+
"@typescript-eslint/eslint-plugin": "^5.4.0",
40+
"@typescript-eslint/parser": "^5.4.0",
41+
"chai": "^4.3.7",
42+
"eslint": "^7.32.0",
43+
"husky": "^7.0.4",
44+
"jest": "^28.1.0",
45+
"mocha": "^10.2.0",
46+
"prettier": "^2.4.1",
47+
"rimraf": "^3.0.2",
48+
"ts-jest": "^28.0.3",
49+
"ts-node": "^10.9.1",
50+
"typescript": "^4.5.5"
51+
}

src/constants.ts

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
"use strict"
1+
'use strict';
22
export const compactProof = false;
33

4+
export const HYPERSIGN_TESTNET_RPC = 'http://localhost:26657';
5+
export const HYPERSIGN_TESTNET_REST = 'http://localhost:1317';
46

5-
export const HYPERSIGN_TESTNET_RPC ="http://localhost:26657"
6-
export const HYPERSIGN_TESTNET_REST="http://localhost:1317"
7+
export const HYPERSIGN_MAINNET_RPC = 'http://localhost:26657';
8+
export const HYPERSIGN_MAINNET_REST = 'http://localhost:1317';
79

8-
export const HYPERSIGN_MAINNET_RPC ="http://localhost:26657"
9-
export const HYPERSIGN_MAINNET_REST="http://localhost:1317"
10-
11-
export const HID_COSMOS_MODULE='/hypersignprotocol.hidnode.ssi'
12-
export const HYPERSIGN_NETWORK_DID_PATH="hypersign-protocol/hidnode/ssi/did"
13-
export const HYPERSIGN_NETWORK_SCHEMA_PATH="hypersign-protocol/hidnode/ssi/schema"
14-
export const HYPERSIGN_NETWORK_CREDENTIALSTATUS_PATH="hypersign-protocol/hidnode/ssi/credential"
15-
export const HYPERSIGN_NETWORK_BANK_BALANCE_PATH="/bank/balances/"
10+
export const HID_COSMOS_MODULE = '/hypersignprotocol.hidnode.ssi';
11+
export const HYPERSIGN_NETWORK_DID_PATH = 'hypersign-protocol/hidnode/ssi/did';
12+
export const HYPERSIGN_NETWORK_SCHEMA_PATH = 'hypersign-protocol/hidnode/ssi/schema';
13+
export const HYPERSIGN_NETWORK_CREDENTIALSTATUS_PATH = 'hypersign-protocol/hidnode/ssi/credential';
14+
export const HYPERSIGN_NETWORK_BANK_BALANCE_PATH = '/bank/balances/';
1615

1716
export enum HIDRpcEnums {
18-
MsgCreateDID = "MsgCreateDID",
19-
MsgUpdateDID = "MsgUpdateDID",
20-
MsgDeactivateDID = "MsgDeactivateDID",
21-
MsgCreateSchema = "MsgCreateSchema",
22-
MsgRegisterCredentialStatus= "MsgRegisterCredentialStatus"
17+
MsgCreateDID = 'MsgCreateDID',
18+
MsgUpdateDID = 'MsgUpdateDID',
19+
MsgDeactivateDID = 'MsgDeactivateDID',
20+
MsgCreateSchema = 'MsgCreateSchema',
21+
MsgRegisterCredentialStatus = 'MsgRegisterCredentialStatus',
2322
}
24-
Object.freeze(HIDRpcEnums)
23+
Object.freeze(HIDRpcEnums);
2524

2625
export enum CredentialStatusEnums {
26+
2727
LIVE = "Live",
2828
REVOKED="Revoked",
2929
SUSPENDED="Suspended"
@@ -38,16 +38,17 @@ export enum CredentialStatusReasonEnums {
3838

3939

4040
export const DID = {
41-
CONTROLLER_CONTEXT: "https://w3id.org/security/v2",
42-
SCHEME: "did",
43-
METHOD: "hid",
44-
NAMESPACE:"devnet", // this is not used
45-
DID_BASE_CONTEXT: "https://www.w3.org/ns/did/v1",
46-
VERIFICATION_METHOD_TYPE: "Ed25519VerificationKey2020"
47-
}
48-
Object.freeze(DID)
41+
CONTROLLER_CONTEXT: 'https://w3id.org/security/v2',
42+
SCHEME: 'did',
43+
METHOD: 'hid',
44+
NAMESPACE: 'devnet', // this is not used
45+
DID_BASE_CONTEXT: 'https://www.w3.org/ns/did/v1',
46+
VERIFICATION_METHOD_TYPE: 'Ed25519VerificationKey2020',
47+
};
48+
Object.freeze(DID);
4949

5050
export const VC = {
51+
5152
SCHEME: "vc",
5253
METHOD: "hid",
5354
NAMESPACE:"devnet",
@@ -66,32 +67,30 @@ export const VC = {
6667
Object.freeze(VC)
6768

6869
export const VP = {
69-
PREFIX: "vp:",
70-
SCHEME: "vp",
71-
METHOD: "hid",
72-
NAMESPACE:"devnet",
73-
}
74-
Object.freeze(VP)
70+
PREFIX: 'vp:',
71+
SCHEME: 'vp',
72+
METHOD: 'hid',
73+
NAMESPACE: 'devnet',
74+
};
75+
Object.freeze(VP);
7576

7677
export const SCHEMA = {
77-
SCHEME: "sch",
78-
METHOD: "hid",
79-
NAMESPACE:"devnet",
80-
SCHEMA_JSON: 'http://json-schema.org/draft-07/schema',
81-
SCHEMA_TYPE: 'https://w3c-ccg.github.io/vc-json-schemas/v1/schema/1.0/schema.json'
82-
}
83-
Object.freeze(SCHEMA)
78+
SCHEME: 'sch',
79+
METHOD: 'hid',
80+
NAMESPACE: 'devnet',
81+
SCHEMA_JSON: 'http://json-schema.org/draft-07/schema',
82+
SCHEMA_TYPE: 'https://w3c-ccg.github.io/vc-json-schemas/v1/schema/1.0/schema.json',
83+
};
84+
Object.freeze(SCHEMA);
8485

8586
export const KEY_HEADERS = {
86-
MULTICODEC_ED25519_PUB_HEADER : new Uint8Array([0xed, 0x01]),
87-
MULTICODEC_ED25519_PRIV_HEADER : new Uint8Array([0x80, 0x26])
88-
}
89-
Object.freeze(KEY_HEADERS)
87+
MULTICODEC_ED25519_PUB_HEADER: new Uint8Array([0xed, 0x01]),
88+
MULTICODEC_ED25519_PRIV_HEADER: new Uint8Array([0x80, 0x26]),
89+
};
90+
Object.freeze(KEY_HEADERS);
9091

91-
export const GAS_PRICE='0.1';
92+
export const GAS_PRICE = '0.1';
9293
export const HID_DECIMAL = 6;
9394
export const HID_DNOMINATION = 'uhid';
94-
export const HID_MIN_GAS='200000'
95-
export const HID_MIN_FEE='5000'
96-
97-
95+
export const HID_MIN_GAS = '200000';
96+
export const HID_MIN_FEE = '5000';

src/did/did.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export default class HypersignDID implements IDID {
135135
throw new Error('HID-SSI-SDK:: Error: params.privateKeyMultibase is required to register a did');
136136
}
137137

138-
if (!params.privateKeyMultibase) {
138+
if (!params.verificationMethodId) {
139139
throw new Error('HID-SSI-SDK:: Error: params.verificationMethodId is required to register a did');
140140
}
141141

@@ -193,7 +193,7 @@ export default class HypersignDID implements IDID {
193193
throw new Error('HID-SSI-SDK:: Error: params.privateKeyMultibase is required to update a did');
194194
}
195195

196-
if (!params.privateKeyMultibase) {
196+
if (!params.verificationMethodId) {
197197
throw new Error('HID-SSI-SDK:: Error: params.verificationMethodId is required to update a did');
198198
}
199199
if (!params.versionId) {
@@ -220,7 +220,7 @@ export default class HypersignDID implements IDID {
220220
throw new Error('HID-SSI-SDK:: Error: params.privateKeyMultibase is required to deactivate a did');
221221
}
222222

223-
if (!params.privateKeyMultibase) {
223+
if (!params.verificationMethodId) {
224224
throw new Error('HID-SSI-SDK:: Error: params.verificationMethodId is required to deactivate a did');
225225
}
226226
if (!params.versionId) {

src/tests/config.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { DirectSecp256k1HdWallet } = require('@cosmjs/proto-signing');
2+
const { HdPath, Slip10RawIndex } = require('@cosmjs/crypto');
3+
4+
export const mnemonic =
5+
'zero require alcohol swamp hover punch celery common merge embrace flock dumb unit capital problem future canal improve auto home apple avoid tragic mechanic';
6+
7+
export const hidNodeEp = {
8+
rpc: 'https://jagrat.hypersign.id/rpc',
9+
rest: 'https://jagrat.hypersign.id/rest',
10+
namespace: 'testnet',
11+
};
12+
export function makeCosmoshubPath(a) {
13+
return [
14+
Slip10RawIndex.hardened(44),
15+
Slip10RawIndex.hardened(118),
16+
Slip10RawIndex.hardened(0),
17+
Slip10RawIndex.normal(0),
18+
Slip10RawIndex.normal(a),
19+
];
20+
}
21+
22+
export const createWallet = async (mnemonic) => {
23+
let options;
24+
if (!mnemonic) {
25+
return await DirectSecp256k1HdWallet.generate(
26+
24,
27+
(options = {
28+
prefix: 'hid',
29+
hdPaths: [makeCosmoshubPath(0)],
30+
})
31+
);
32+
} else {
33+
return await DirectSecp256k1HdWallet.fromMnemonic(
34+
mnemonic,
35+
(options = {
36+
prefix: 'hid',
37+
hdPaths: [makeCosmoshubPath(0)],
38+
})
39+
);
40+
}
41+
};

0 commit comments

Comments
 (0)