Skip to content

Commit

Permalink
Merge pull request #511 from docknetwork/ver-method-ref-match
Browse files Browse the repository at this point in the history
Move `getVerificationMethod` logic to the `CustomLinkedDataSignature`
  • Loading branch information
cykoder authored Jan 27, 2025
2 parents 9f6418d + 267c5d5 commit a4e5578
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 69 deletions.
13 changes: 13 additions & 0 deletions examples/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @docknetwork/sdk-examples

## 0.15.0

### Minor Changes

- Move `getVerificationMethod` logic to the `CustomLinkedDataSignature`

### Patch Changes

- Updated dependencies
- @docknetwork/dock-blockchain-modules@0.21.0
- @docknetwork/dock-blockchain-api@0.17.0
- @docknetwork/credential-sdk@0.32.0

## 0.14.0

### Minor Changes
Expand Down
8 changes: 4 additions & 4 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@docknetwork/sdk-examples",
"private": true,
"type": "module",
"version": "0.14.0",
"version": "0.15.0",
"scripts": {
"bbs-dock-example": "babel-node ./bbs-dock.js",
"claim-deduction-example": "babel-node ./claim-deduction.js",
Expand All @@ -19,9 +19,9 @@
"lint": "eslint \"*.js\""
},
"dependencies": {
"@docknetwork/credential-sdk": "0.31.0",
"@docknetwork/dock-blockchain-api": "0.16.0",
"@docknetwork/dock-blockchain-modules": "0.20.0"
"@docknetwork/credential-sdk": "0.32.0",
"@docknetwork/dock-blockchain-api": "0.17.0",
"@docknetwork/dock-blockchain-modules": "0.21.0"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/cheqd-blockchain-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @docknetwork/cheqd-blockchain-api

## 0.26.0

### Minor Changes

- Move `getVerificationMethod` logic to the `CustomLinkedDataSignature`

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.32.0

## 0.25.0

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/cheqd-blockchain-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/cheqd-blockchain-api",
"version": "0.25.0",
"version": "0.26.0",
"license": "MIT",
"main": "./dist/esm/index.js",
"type": "module",
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"@cheqd/sdk": "cjs",
"@docknetwork/credential-sdk": "0.31.0"
"@docknetwork/credential-sdk": "0.32.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand Down
11 changes: 11 additions & 0 deletions packages/cheqd-blockchain-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @docknetwork/cheqd-blockchain-modules

## 0.23.0

### Minor Changes

- Move `getVerificationMethod` logic to the `CustomLinkedDataSignature`

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.32.0

## 0.22.0

### Minor Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/cheqd-blockchain-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/cheqd-blockchain-modules",
"version": "0.22.0",
"version": "0.23.0",
"type": "module",
"license": "MIT",
"main": "./dist/esm/index.js",
Expand Down Expand Up @@ -33,7 +33,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.31.0"
"@docknetwork/credential-sdk": "0.32.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand All @@ -42,7 +42,7 @@
"@babel/plugin-syntax-import-attributes": "^7.25.6",
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
"@babel/preset-env": "^7.24.3",
"@docknetwork/cheqd-blockchain-api": "0.25.0",
"@docknetwork/cheqd-blockchain-api": "0.26.0",
"@rollup/plugin-alias": "^4.0.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/credential-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @docknetwork/credential-sdk

## 0.32.0

### Minor Changes

- Move `getVerificationMethod` logic to the `CustomLinkedDataSignature`

## 0.31.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/credential-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/credential-sdk",
"version": "0.31.0",
"version": "0.32.0",
"license": "MIT",
"type": "module",
"files": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import jsigs from 'jsonld-signatures';
import base58btc from 'bs58';
import base64url from 'base64url';
import jsonld from 'jsonld';
import { possibleVerificationMethodRefs } from '../../../types/did/document/verification-method-ref';
import { createJws } from '../../jws';

const MULTIBASE_BASE58BTC_HEADER = 'z';
Expand All @@ -27,6 +29,58 @@ export default class CustomLinkedDataSignature extends jsigs.suites
this.useProofValue = config.useProofValue || false;
}

/**
* @param document {object} to be signed.
* @param proof {object}
* @param documentLoader {function}
*/
static async getVerificationMethod({ proof, documentLoader }) {
let { verificationMethod } = proof;
if (typeof verificationMethod === 'object') {
verificationMethod = verificationMethod.id;
}
if (!verificationMethod) {
throw new Error('No "verificationMethod" found in proof.');
}

// Note: `expansionMap` is intentionally not passed; we can safely drop
// properties here and must allow for it
const result = await jsonld.frame(
verificationMethod,
{
'@context': jsigs.SECURITY_CONTEXT_URL,
'@embed': '@always',
id: possibleVerificationMethodRefs(verificationMethod),
},
{
documentLoader,
compactToRelative: false,
expandContext: jsigs.SECURITY_CONTEXT_URL,
},
);

if (!result) {
throw new Error(`Verification method ${verificationMethod} not found.`);
}
// ensure verification method has not been revoked
if (result.revoked !== undefined) {
throw new Error('The verification method has been revoked.');
}
return result;
}

/**
* @param document {object} to be signed.
* @param proof {object}
* @param documentLoader {function}
*/
async getVerificationMethod({ proof, documentLoader }) {
return this.constructor.getVerificationMethod({
proof,
documentLoader,
});
}

/**
* Verifies the proof signature against the given data.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
DefaultSchemaParsingOpts,
} from '@docknetwork/crypto-wasm-ts';

import jsonld from 'jsonld';
import jsigs from 'jsonld-signatures';

import stringify from 'json-stringify-deterministic';
Expand All @@ -13,7 +12,6 @@ import { u8aToU8a } from '../../../utils/bytes';
import { withExtendedStaticProperties } from '../../../utils/inheritance';
import CustomLinkedDataSignature from './CustomLinkedDataSignature';
import { deepClone } from '../../../utils/misc';
import { possibleVerificationMethodRefs } from '../../../types/did/document/verification-method-ref';

const SUITE_CONTEXT_URL = 'https://www.w3.org/2018/credentials/v1';

Expand Down Expand Up @@ -531,58 +529,6 @@ export default withExtendedStaticProperties(
return newSchemaJson;
}

/**
* @param document {object} to be signed.
* @param proof {object}
* @param documentLoader {function}
*/
static async getVerificationMethod({ proof, documentLoader }) {
let { verificationMethod } = proof;
if (typeof verificationMethod === 'object') {
verificationMethod = verificationMethod.id;
}
if (!verificationMethod) {
throw new Error('No "verificationMethod" found in proof.');
}

// Note: `expansionMap` is intentionally not passed; we can safely drop
// properties here and must allow for it
const result = await jsonld.frame(
verificationMethod,
{
'@context': jsigs.SECURITY_CONTEXT_URL,
'@embed': '@always',
id: possibleVerificationMethodRefs(verificationMethod),
},
{
documentLoader,
compactToRelative: false,
expandContext: jsigs.SECURITY_CONTEXT_URL,
},
);

if (!result) {
throw new Error(`Verification method ${verificationMethod} not found.`);
}
// ensure verification method has not been revoked
if (result.revoked !== undefined) {
throw new Error('The verification method has been revoked.');
}
return result;
}

/**
* @param document {object} to be signed.
* @param proof {object}
* @param documentLoader {function}
*/
async getVerificationMethod({ proof, documentLoader }) {
return this.constructor.getVerificationMethod({
proof,
documentLoader,
});
}

/**
* Generate object with `sign` method
* @param keypair
Expand Down
11 changes: 11 additions & 0 deletions packages/dock-blockchain-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @docknetwork/dock-blockchain-api

## 0.17.0

### Minor Changes

- Move `getVerificationMethod` logic to the `CustomLinkedDataSignature`

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.32.0

## 0.16.0

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/dock-blockchain-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/dock-blockchain-api",
"version": "0.16.0",
"version": "0.17.0",
"license": "MIT",
"main": "./dist/esm/index.js",
"type": "module",
Expand Down Expand Up @@ -89,7 +89,7 @@
"@polkadot/api": "10.12.4"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.31.0",
"@docknetwork/credential-sdk": "0.32.0",
"@docknetwork/node-types": "^0.17.0",
"@juanelas/base64": "^1.0.5",
"@polkadot/api": "10.12.4",
Expand Down
11 changes: 11 additions & 0 deletions packages/dock-blockchain-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @docknetwork/dock-blockchain-modules

## 0.21.0

### Minor Changes

- Move `getVerificationMethod` logic to the `CustomLinkedDataSignature`

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.32.0

## 0.20.0

### Minor Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/dock-blockchain-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/dock-blockchain-modules",
"version": "0.20.0",
"version": "0.21.0",
"license": "MIT",
"type": "module",
"main": "./dist/esm/index.js",
Expand Down Expand Up @@ -33,7 +33,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.31.0"
"@docknetwork/credential-sdk": "0.32.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand All @@ -42,7 +42,7 @@
"@babel/plugin-syntax-import-attributes": "^7.25.6",
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
"@babel/preset-env": "^7.24.3",
"@docknetwork/dock-blockchain-api": "0.16.0",
"@docknetwork/dock-blockchain-api": "0.17.0",
"@rollup/plugin-alias": "^4.0.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down

0 comments on commit a4e5578

Please sign in to comment.