Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/decode-uri-compone…
Browse files Browse the repository at this point in the history
…nt-0.2.2
  • Loading branch information
cykoder authored Mar 14, 2024
2 parents d91a376 + 31c6473 commit 9285ab1
Show file tree
Hide file tree
Showing 208 changed files with 20,655 additions and 6,607 deletions.
8 changes: 7 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ node_modules
dist
build
tests
tutorial
tutorials
.github
.env
docker
.editorconfig
.eslintrc.json
.git
.npmrc
env_example
10 changes: 9 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"plugins": ["jest", "sonarjs"],
"plugins": ["jest", "sonarjs", "unused-imports"],
"globals": {
"process": "readonly"
},
Expand All @@ -8,11 +8,13 @@
"es6": true
},
"extends": ["plugin:sonarjs/recommended", "eslint:recommended", "plugin:jest/recommended", "airbnb-base"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_", "caughtErrorsIgnorePattern": "^_" }],
"no-use-before-define": [
"error",
{
Expand All @@ -21,10 +23,16 @@
"variables": true
}
],
"unused-imports/no-unused-imports": "error",
"no-void": "off",
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
"import/no-extraneous-dependencies": "off",
"import/prefer-default-export": "off",
"class-methods-use-this": "off",
"no-return-await": "off",
"no-bitwise": ["error", { "allow": ["~"] }],
"no-plusplus": "off",
"no-restricted-properties": "off",
"max-len": "off",
"no-console": "off",
"no-else-return": "off",
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/integrations-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
mainnet:
runs-on: ubuntu-latest
env:
DisableDidKeyAndTrustRegistryTests: true
CONFIG_DOCK_NODE_IMAGE_TAG: 'mainnet'
steps:
- uses: actions/checkout@v2
Expand All @@ -39,8 +40,8 @@ jobs:
testnet:
runs-on: ubuntu-latest
env:
DisableDidKeyAndTrustRegistryTests: true
CONFIG_DOCK_NODE_IMAGE_TAG: 'testnet'
DISABLE_DEMOCRACY_PREIMAGE_TESTS: true
steps:
- uses: actions/checkout@v2
- uses: ibnesayeed/[email protected]
Expand Down
1 change: 1 addition & 0 deletions .jsdoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"allowUnknownTags": true,
"dictionaries": ["jsdoc","closure"]
},
"plugins": ["node_modules/jsdoc-typeof-plugin"],
"templates": {
"cleverLinks": false,
"monospaceLinks": false
Expand Down
5 changes: 3 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = {
plugins: ["@babel/plugin-transform-modules-commonjs"],
presets: [
[
'@babel/preset-env',
"@babel/preset-env",
{
targets: {
node: 'current',
node: "current",
},
},
],
Expand Down
9 changes: 3 additions & 6 deletions docker/staking_payouts/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
FROM node:14-stretch AS builder
FROM node:16.6.0-buster AS builder
WORKDIR /usr/app

COPY . .

RUN yarn
RUN yarn build-scripts

FROM public.ecr.aws/lambda/nodejs:14
FROM public.ecr.aws/lambda/nodejs:16

COPY --from=builder [ "/usr/app/build/scripts/staking_payouts.js", "/usr/app/yarn.lock", "/usr/app/package.json", "./" ]

RUN npm i -g yarn
RUN yarn
COPY --from=builder [ "/usr/app/build/*", "./" ]

CMD [ "staking_payouts.handler" ]
115 changes: 59 additions & 56 deletions example/bbs-dock.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import VerifiableCredential from '../src/verifiable-credential';
import { MultiResolver } from '../src/resolver';
import { DIDResolver } from '../src/resolver';
import Bls12381G2KeyPairDock2022 from '../src/utils/vc/crypto/Bls12381G2KeyPairDock2022';

const keypairOpts = {
"id": "did:example:489398593#keys-1",
"controller": "did:example:489398593",
"privateKeyBase58": "23fKPbbSJ7tCJVDYynRZQ1wPs6GannD2dEMjKZnFtKxy",
"publicKeyBase58": "GzJYyMYXQyAdmRK3JcfQnHJtz5TyRiYyYtfj6SZD9LQ4zDapQ3qeC1AaBwCtzhQ8En6EGiLe7ke2RaeLNTxJ9GVompK6j6kHB8e5m2ya5qdCB2bbNMVii99QfmYsbj36J3B"
id: 'did:example:489398593#keys-1',
controller: 'did:example:489398593',
privateKeyBase58: '23fKPbbSJ7tCJVDYynRZQ1wPs6GannD2dEMjKZnFtKxy',
publicKeyBase58: 'GzJYyMYXQyAdmRK3JcfQnHJtz5TyRiYyYtfj6SZD9LQ4zDapQ3qeC1AaBwCtzhQ8En6EGiLe7ke2RaeLNTxJ9GVompK6j6kHB8e5m2ya5qdCB2bbNMVii99QfmYsbj36J3B',
};

class ExampleDIDResolver {
class ExampleDIDResolver extends DIDResolver {
static METHOD = 'example';

constructor() {
super(void 0);
}

async resolve(did) {
if (did.indexOf('#keys-1') !== -1) {
return {
Expand All @@ -18,43 +24,41 @@ class ExampleDIDResolver {
};
}
return {
"@context": "https://w3id.org/security/v2",
"id": did,
"assertionMethod": [`${did}#keys-1`]
'@context': 'https://w3id.org/security/v2',
id: did,
assertionMethod: [`${did}#keys-1`],
};
}
}

const resolver = new MultiResolver({
example: new ExampleDIDResolver(),
});
const resolver = new ExampleDIDResolver();

const residentCardSchema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://ld.dock.io/examples/resident-card-schema.json",
"title": "Resident Card Example",
"type": "object",
"properties": {
"credentialSubject": {
"type": "object",
"properties": {
"givenName": {
"title": "Given Name",
"type": "string"
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://ld.dock.io/examples/resident-card-schema.json',
title: 'Resident Card Example',
type: 'object',
properties: {
credentialSubject: {
type: 'object',
properties: {
givenName: {
title: 'Given Name',
type: 'string',
},
"familyName": {
"title": "Family Name",
"type": "string"
familyName: {
title: 'Family Name',
type: 'string',
},
lprNumber: {
title: 'LPR Number',
type: 'integer',
minimum: 0,
},
"lprNumber": {
"title": "LPR Number",
"type": "integer",
"minimum": 0
}
},
"required": []
}
}
required: [],
},
},
};

const embeddedSchema = {
Expand All @@ -64,29 +68,29 @@ const embeddedSchema = {

// Defining schema allows to specify custom encoding
const example = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/citizenship/v1",
"https://ld.dock.io/security/bbs/v1"
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://w3id.org/citizenship/v1',
'https://ld.dock.io/security/bbs/v1',
],
"id": "https://issuer.oidp.uscis.gov/credentials/83627465",
"type": ["VerifiableCredential", "PermanentResidentCard"],
"issuer": {
"id": "did:example:489398593"
id: 'https://issuer.oidp.uscis.gov/credentials/83627465',
type: ['VerifiableCredential', 'PermanentResidentCard'],
issuer: {
id: 'did:example:489398593',
},
credentialSchema: embeddedSchema,
identifier: '83627465',
name: 'Permanent Resident Card',
description: 'Government of Example Permanent Resident Card.',
issuanceDate: '2019-12-03T12:19:52Z',
expirationDate: '2029-12-03T12:19:52Z',
credentialSubject: {
id: 'did:example:b34ca6cd37bbf23',
type: ['PermanentResident', 'Person'],
givenName: 'JOHN',
familyName: 'SMITH',
lprNumber: 1234,
},
"credentialSchema": embeddedSchema,
"identifier": "83627465",
"name": "Permanent Resident Card",
"description": "Government of Example Permanent Resident Card.",
"issuanceDate": "2019-12-03T12:19:52Z",
"expirationDate": "2029-12-03T12:19:52Z",
"credentialSubject": {
"id": "did:example:b34ca6cd37bbf23",
"type": ["PermanentResident", "Person"],
"givenName": "JOHN",
"familyName": "SMITH",
"lprNumber": 1234,
}
};

async function signAndVerify(credentialJSON) {
Expand All @@ -106,7 +110,6 @@ async function signAndVerify(credentialJSON) {
// Verify the credential
const verifyResult = await credential.verify({
resolver,
forceRevocationCheck: false,
});

if (verifyResult.verified) {
Expand Down
9 changes: 4 additions & 5 deletions example/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { u8aToString } from '@polkadot/util';

import { DockAPI } from '../src/index';
import { DockBlobIdByteSize } from '../src/modules/blob';
import { createNewDockDID } from '../src/utils/did';
import { getPublicKeyFromKeyringPair } from '../src/utils/misc';
import { createNewDockDID, DidKeypair } from '../src/utils/did';

// The following can be tweaked depending on where the node is running and what
// account is to be used for sending the transaction.
Expand All @@ -20,7 +19,7 @@ async function writeAndReadBlob(dock, blobValue, dockDID, pair) {
blob: blobValue,
};

await dock.blob.new(blob, dockDID, pair, 1, { didModule: dock.did }, false);
await dock.blob.new(blob, dockDID, pair, { didModule: dock.did }, false);

console.log('Blob written, reading from chain...');

Expand All @@ -33,7 +32,7 @@ async function createAuthorDID(dock, pair) {
console.log('Creating new author DID', dockDID);

// Create an author DID to write with
const publicKey = getPublicKeyFromKeyringPair(pair);
const publicKey = pair.publicKey();
const didKey = new DidKey(publicKey, new VerificationRelationship());
await dock.did.new(dockDID, [didKey], [], false);
return dockDID;
Expand All @@ -57,7 +56,7 @@ async function main() {
const dock = await connectToNode();

// Generate keypair for DID
const pair = dock.keyring.addFromUri(randomAsHex(32));
const pair = DidKeypair.fromApi(dock);

// Generate a DID to be used as author
const dockDID = await createAuthorDID(dock, pair);
Expand Down
22 changes: 11 additions & 11 deletions example/dock-did.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import dock, {
} from '../src/index';
import {
createNewDockDID,
DidKeypair,
} from '../src/utils/did';
import { getPublicKeyFromKeyringPair } from '../src/utils/misc';

// The following can be tweaked depending on where the node is running and what
// account is to be used for sending the transaction.
Expand All @@ -31,17 +31,17 @@ async function removeDID() {
console.log('Removing DID now.');

// Sign the DID removal with this key pair as this is the current key of the DID
const pair = dock.keyring.addFromUri(firstKeySeed, null, 'sr25519');
const pair = new DidKeypair(dock.keyring.addFromUri(firstKeySeed, null, 'sr25519'), 1);

return dock.did.remove(dockDID, dockDID, pair, 1, undefined, false);
return dock.did.remove(dockDID, dockDID, pair, undefined, false);
}

// This function assumes the DID has been written.
async function addServiceEndpoint() {
console.log('Add new service endpoint now.');

// Sign key update with this key pair as this is the current key of the DID
const pair = dock.keyring.addFromUri(firstKeySeed, null, 'sr25519');
const pair = new DidKeypair(dock.keyring.addFromUri(firstKeySeed, null, 'sr25519'), 1);

const spType = new ServiceEndpointType();
spType.setLinkedDomains();
Expand All @@ -50,38 +50,38 @@ async function addServiceEndpoint() {
const spId = u8aToHex(encoder.encode(spIdText));
const originsText = ['https://foo.example.com'];
const origins = originsText.map((u) => u8aToHex(encoder.encode(u)));
return dock.did.addServiceEndpoint(spId, spType, origins, dockDID, dockDID, pair, 1, undefined, false);
return dock.did.addServiceEndpoint(spId, spType, origins, dockDID, dockDID, pair, undefined, false);
}

// This function assumes the DID has been written.
async function addController() {
console.log('Add new controller now.');

// Sign key update with this key pair as this is the current key of the DID
const pair = dock.keyring.addFromUri(firstKeySeed, null, 'sr25519');
const pair = new DidKeypair(dock.keyring.addFromUri(firstKeySeed, null, 'sr25519'), 1);

const newController = createNewDockDID();

return dock.did.addControllers([newController], dockDID, dockDID, pair, 1, undefined, false);
return dock.did.addControllers([newController], dockDID, dockDID, pair, undefined, false);
}

// This function assumes the DID has been written.
async function addKey() {
console.log('Add new key now.');

// Sign key update with this key pair as this is the current key of the DID
const pair = dock.keyring.addFromUri(firstKeySeed, null, 'sr25519');
const pair = new DidKeypair(dock.keyring.addFromUri(firstKeySeed, null, 'sr25519'), 1);

// Update DID key to the following
const newPair = dock.keyring.addFromUri(secondKeySeed, null, 'ed25519');
const newPair = new DidKeypair(dock.keyring.addFromUri(secondKeySeed, null, 'ed25519'), 1);
// the following function will figure out the correct PublicKey type from the `type` property of `newPair`
const newPk = getPublicKeyFromKeyringPair(newPair);
const newPk = newPair.publicKey();

const vr = new VerificationRelationship();
vr.setAuthentication();
const newDidKey = new DidKey(newPk, vr);

return dock.did.addKeys([newDidKey], dockDID, dockDID, pair, 1, undefined, false);
return dock.did.addKeys([newDidKey], dockDID, dockDID, pair, undefined, false);
}

async function getDIDDoc() {
Expand Down
Loading

0 comments on commit 9285ab1

Please sign in to comment.