Skip to content

Commit

Permalink
Merge pull request #75 from hypersign-protocol/issues#74
Browse files Browse the repository at this point in the history
test case using chai and mocha
  • Loading branch information
Pratap2018 authored Dec 19, 2022
2 parents 2bf71c7 + a5244f8 commit 907badc
Show file tree
Hide file tree
Showing 9 changed files with 1,862 additions and 96 deletions.
96 changes: 50 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
{
"name": "hs-ssi-sdk",
"version": "6.2.0",
"description": "sdk is an implementation of proposed DID by W3C",
"main": "build/src/index.js",
"scripts": {
"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",
"start": "node build/index.js",
"build": "npm run lint:fix && npm run prettier && rimraf build && tsc -p .",
"prettier": "prettier --config .prettierrc.json --write src/**/*.ts",
"prepublish": "npm run build",
"lint": "eslint . --ext .ts",
"lint:fix": "npm run lint -- --fix",
"prepare": "husky install"
},
"author": "Hypersign Team",
"license": "ISC",
"dependencies": {
"@cosmjs/proto-signing": "^0.27.0",
"@cosmjs/stargate": "^0.27.0",
"@digitalbazaar/ed25519-signature-2020": "^3.0.0",
"@digitalbazaar/ed25519-verification-key-2018": "^3.1.2",
"@digitalbazaar/ed25519-verification-key-2020": "^3.3.0",
"@stablelib/ed25519": "^1.0.2",
"axios": "^0.19.0",
"crypto-ld": "^6.0.0",
"jsonld": "^3.1.1",
"jsonld-signatures": "^9.0.0",
"node-fetch": "^2.6.1",
"protobufjs": "^6.11.2",
"uuid": "^8.3.0",
"vc-js": "https://github.com/hypersign-protocol/vc-js"
},
"devDependencies": {
"@types/jest": "^27.5.1",
"@types/node": "^14.11.2",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"eslint": "^7.32.0",
"husky": "^7.0.4",
"jest": "^28.1.0",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.3",
"typescript": "^4.5.5"
}
}
"name": "hs-ssi-sdk",
"version": "6.2.0",
"description": "sdk is an implementation of proposed DID by W3C",
"main": "build/src/index.js",
"scripts": {
"test": "cd test/ssi && node did.js && node private-did.js && node schema.js && cd credentials && node test1.js && node test2.js",
"test_chai": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'src/tests/*.ts' --exit --timeout 40000",
"start": "node build/index.js",
"build": "npm run lint:fix && npm run prettier && rimraf build && tsc -p .",
"prettier": "prettier --config .prettierrc.json --write src/**/*.ts",
"prepublish": "npm run build",
"lint": "eslint . --ext .ts",
"lint:fix": "npm run lint -- --fix",
"prepare": "husky install"
},
"author": "Hypersign Team",
"license": "ISC",
"dependencies": {
"@cosmjs/proto-signing": "^0.27.0",
"@cosmjs/stargate": "^0.27.0",
"@digitalbazaar/ed25519-signature-2020": "^3.0.0",
"@digitalbazaar/ed25519-verification-key-2018": "^3.1.2",
"@digitalbazaar/ed25519-verification-key-2020": "^3.3.0",
"@stablelib/ed25519": "^1.0.2",
"axios": "^0.19.0",
"crypto-ld": "^6.0.0",
"jsonld": "^3.1.1",
"jsonld-signatures": "^9.0.0",
"node-fetch": "^2.6.1",
"protobufjs": "^6.11.2",
"uuid": "^8.3.0",
"vc-js": "https://github.com/hypersign-protocol/vc-js"
},
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^14.11.2",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"chai": "^4.3.7",
"eslint": "^7.32.0",
"husky": "^7.0.4",
"jest": "^28.1.0",
"mocha": "^10.2.0",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.5.5"
}
93 changes: 46 additions & 47 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
"use strict"
'use strict';
export const compactProof = false;

export const HYPERSIGN_TESTNET_RPC = 'http://localhost:26657';
export const HYPERSIGN_TESTNET_REST = 'http://localhost:1317';

export const HYPERSIGN_TESTNET_RPC ="http://localhost:26657"
export const HYPERSIGN_TESTNET_REST="http://localhost:1317"
export const HYPERSIGN_MAINNET_RPC = 'http://localhost:26657';
export const HYPERSIGN_MAINNET_REST = 'http://localhost:1317';

export const HYPERSIGN_MAINNET_RPC ="http://localhost:26657"
export const HYPERSIGN_MAINNET_REST="http://localhost:1317"

export const HID_COSMOS_MODULE='/hypersignprotocol.hidnode.ssi'
export const HYPERSIGN_NETWORK_DID_PATH="hypersign-protocol/hidnode/ssi/did"
export const HYPERSIGN_NETWORK_SCHEMA_PATH="hypersign-protocol/hidnode/ssi/schema"
export const HYPERSIGN_NETWORK_CREDENTIALSTATUS_PATH="hypersign-protocol/hidnode/ssi/credential"
export const HYPERSIGN_NETWORK_BANK_BALANCE_PATH="/bank/balances/"
export const HID_COSMOS_MODULE = '/hypersignprotocol.hidnode.ssi';
export const HYPERSIGN_NETWORK_DID_PATH = 'hypersign-protocol/hidnode/ssi/did';
export const HYPERSIGN_NETWORK_SCHEMA_PATH = 'hypersign-protocol/hidnode/ssi/schema';
export const HYPERSIGN_NETWORK_CREDENTIALSTATUS_PATH = 'hypersign-protocol/hidnode/ssi/credential';
export const HYPERSIGN_NETWORK_BANK_BALANCE_PATH = '/bank/balances/';

export enum HIDRpcEnums {
MsgCreateDID = "MsgCreateDID",
MsgUpdateDID = "MsgUpdateDID",
MsgDeactivateDID = "MsgDeactivateDID",
MsgCreateSchema = "MsgCreateSchema",
MsgRegisterCredentialStatus= "MsgRegisterCredentialStatus"
MsgCreateDID = 'MsgCreateDID',
MsgUpdateDID = 'MsgUpdateDID',
MsgDeactivateDID = 'MsgDeactivateDID',
MsgCreateSchema = 'MsgCreateSchema',
MsgRegisterCredentialStatus = 'MsgRegisterCredentialStatus',
}
Object.freeze(HIDRpcEnums)
Object.freeze(HIDRpcEnums);

export enum CredentialStatusEnums {

LIVE = "Live",
REVOKED="Revoked",
SUSPENDED="Suspended"
Expand All @@ -38,16 +38,17 @@ export enum CredentialStatusReasonEnums {


export const DID = {
CONTROLLER_CONTEXT: "https://w3id.org/security/v2",
SCHEME: "did",
METHOD: "hid",
NAMESPACE:"devnet", // this is not used
DID_BASE_CONTEXT: "https://www.w3.org/ns/did/v1",
VERIFICATION_METHOD_TYPE: "Ed25519VerificationKey2020"
}
Object.freeze(DID)
CONTROLLER_CONTEXT: 'https://w3id.org/security/v2',
SCHEME: 'did',
METHOD: 'hid',
NAMESPACE: 'devnet', // this is not used
DID_BASE_CONTEXT: 'https://www.w3.org/ns/did/v1',
VERIFICATION_METHOD_TYPE: 'Ed25519VerificationKey2020',
};
Object.freeze(DID);

export const VC = {

SCHEME: "vc",
METHOD: "hid",
NAMESPACE:"devnet",
Expand All @@ -66,32 +67,30 @@ export const VC = {
Object.freeze(VC)

export const VP = {
PREFIX: "vp:",
SCHEME: "vp",
METHOD: "hid",
NAMESPACE:"devnet",
}
Object.freeze(VP)
PREFIX: 'vp:',
SCHEME: 'vp',
METHOD: 'hid',
NAMESPACE: 'devnet',
};
Object.freeze(VP);

export const SCHEMA = {
SCHEME: "sch",
METHOD: "hid",
NAMESPACE:"devnet",
SCHEMA_JSON: 'http://json-schema.org/draft-07/schema',
SCHEMA_TYPE: 'https://w3c-ccg.github.io/vc-json-schemas/v1/schema/1.0/schema.json'
}
Object.freeze(SCHEMA)
SCHEME: 'sch',
METHOD: 'hid',
NAMESPACE: 'devnet',
SCHEMA_JSON: 'http://json-schema.org/draft-07/schema',
SCHEMA_TYPE: 'https://w3c-ccg.github.io/vc-json-schemas/v1/schema/1.0/schema.json',
};
Object.freeze(SCHEMA);

export const KEY_HEADERS = {
MULTICODEC_ED25519_PUB_HEADER : new Uint8Array([0xed, 0x01]),
MULTICODEC_ED25519_PRIV_HEADER : new Uint8Array([0x80, 0x26])
}
Object.freeze(KEY_HEADERS)
MULTICODEC_ED25519_PUB_HEADER: new Uint8Array([0xed, 0x01]),
MULTICODEC_ED25519_PRIV_HEADER: new Uint8Array([0x80, 0x26]),
};
Object.freeze(KEY_HEADERS);

export const GAS_PRICE='0.1';
export const GAS_PRICE = '0.1';
export const HID_DECIMAL = 6;
export const HID_DNOMINATION = 'uhid';
export const HID_MIN_GAS='200000'
export const HID_MIN_FEE='5000'


export const HID_MIN_GAS = '200000';
export const HID_MIN_FEE = '5000';
6 changes: 3 additions & 3 deletions src/did/did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default class HypersignDID implements IDID {
throw new Error('HID-SSI-SDK:: Error: params.privateKeyMultibase is required to register a did');
}

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

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

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

if (!params.privateKeyMultibase) {
if (!params.verificationMethodId) {
throw new Error('HID-SSI-SDK:: Error: params.verificationMethodId is required to deactivate a did');
}
if (!params.versionId) {
Expand Down
41 changes: 41 additions & 0 deletions src/tests/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { DirectSecp256k1HdWallet } = require('@cosmjs/proto-signing');
const { HdPath, Slip10RawIndex } = require('@cosmjs/crypto');

export const mnemonic =
'zero require alcohol swamp hover punch celery common merge embrace flock dumb unit capital problem future canal improve auto home apple avoid tragic mechanic';

export const hidNodeEp = {
rpc: 'https://jagrat.hypersign.id/rpc',
rest: 'https://jagrat.hypersign.id/rest',
namespace: 'testnet',
};
export function makeCosmoshubPath(a) {
return [
Slip10RawIndex.hardened(44),
Slip10RawIndex.hardened(118),
Slip10RawIndex.hardened(0),
Slip10RawIndex.normal(0),
Slip10RawIndex.normal(a),
];
}

export const createWallet = async (mnemonic) => {
let options;
if (!mnemonic) {
return await DirectSecp256k1HdWallet.generate(
24,
(options = {
prefix: 'hid',
hdPaths: [makeCosmoshubPath(0)],
})
);
} else {
return await DirectSecp256k1HdWallet.fromMnemonic(
mnemonic,
(options = {
prefix: 'hid',
hdPaths: [makeCosmoshubPath(0)],
})
);
}
};
Loading

0 comments on commit 907badc

Please sign in to comment.