Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @docknetwork/sdk-examples

## 0.22.5

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.55.0
- @docknetwork/cheqd-blockchain-api@5.0.0
- @docknetwork/cheqd-blockchain-modules@5.0.0

## 0.22.4

### Patch 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.22.4",
"version": "0.22.5",
"scripts": {
"bbs-dock-example": "babel-node ./src/bbs-dock.js",
"claim-deduction-example": "babel-node ./src/claim-deduction.js",
Expand All @@ -18,9 +18,9 @@
"lint": "eslint \"src/**/*.js\""
},
"dependencies": {
"@docknetwork/credential-sdk": "0.54.19",
"@docknetwork/cheqd-blockchain-api": "4.2.2",
"@docknetwork/cheqd-blockchain-modules": "4.0.9"
"@docknetwork/credential-sdk": "0.55.0",
"@docknetwork/cheqd-blockchain-api": "5.0.0",
"@docknetwork/cheqd-blockchain-modules": "5.0.0"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/cheqd-blockchain-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @docknetwork/cheqd-blockchain-api

## 5.0.0

### Patch Changes

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

## 4.2.2

### Patch Changes
Expand Down
6 changes: 3 additions & 3 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": "4.2.2",
"version": "5.0.0",
"license": "MIT",
"main": "./dist/esm/index.js",
"type": "module",
Expand Down Expand Up @@ -32,7 +32,7 @@
"node": ">=22.0.0"
},
"peerDependencies": {
"@docknetwork/credential-sdk": "^0.54.19"
"@docknetwork/credential-sdk": "^0.55.0"
},
"dependencies": {
"@cheqd/sdk": "5.5.0",
Expand All @@ -46,7 +46,7 @@
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
"@babel/preset-env": "^7.24.3",
"@comunica/types": "^1.0.0",
"@docknetwork/credential-sdk": "^0.54.19",
"@docknetwork/credential-sdk": "^0.55.0",
"@helia/strings": "^3.0.1",
"@rollup/plugin-alias": "^4.0.2",
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/cheqd-blockchain-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @docknetwork/cheqd-blockchain-modules

## 5.0.0

### Patch Changes

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

## 4.0.9

### Patch Changes
Expand Down
8 changes: 4 additions & 4 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": "4.0.9",
"version": "5.0.0",
"type": "module",
"license": "MIT",
"main": "./dist/esm/index.js",
Expand Down Expand Up @@ -32,7 +32,7 @@
"node": ">=22.0.0"
},
"peerDependencies": {
"@docknetwork/credential-sdk": "^0.54.19"
"@docknetwork/credential-sdk": "^0.55.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand All @@ -41,8 +41,8 @@
"@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": "4.2.2",
"@docknetwork/credential-sdk": "^0.54.19",
"@docknetwork/cheqd-blockchain-api": "5.0.0",
"@docknetwork/credential-sdk": "^0.55.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.55.0

### Minor Changes

- secp256r1 key support

## 0.54.19

### Patch 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.54.19",
"version": "0.55.0",
"license": "MIT",
"type": "module",
"files": [
Expand Down
1 change: 1 addition & 0 deletions packages/credential-sdk/src/keypairs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as DockKeypair } from './dock-keypair';
export { default as Ed25519Keypair } from './keypair-ed25519';
export { default as Secp256k1Keypair } from './keypair-secp256k1';
export { default as Secp256r1Keypair } from './keypair-secp256r1';
export { default as DidKeypair } from './did-keypair';
123 changes: 123 additions & 0 deletions packages/credential-sdk/src/keypairs/keypair-secp256r1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import elliptic from 'elliptic';
import { sha256 } from 'js-sha256';

import { SignatureSecp256r1 } from '../types/signatures';
import { EcdsaSecp256r1VerKeyName } from '../vc/crypto/constants';
import DockKeypair from './dock-keypair';
import { hexToU8a, normalizeToU8a, valueBytes } from '../utils';

const EC = elliptic.ec;
const secp256r1Curve = new EC('p256');

function encodeDERInt(intBytes) {
let i = 0;
while (i < intBytes.length && intBytes[i] === 0) {
i++;
}

let trimmedBytes = intBytes.slice(i);

// eslint-disable-next-line no-bitwise
if (trimmedBytes[0] & 0x80) {
trimmedBytes = Uint8Array.of(0, ...trimmedBytes);
}

const { length } = trimmedBytes;
return [0x02, length, ...trimmedBytes];
}

export default class Secp256r1Keypair extends DockKeypair {
static Signature = SignatureSecp256r1;

static VerKeyType = EcdsaSecp256r1VerKeyName;

static SeedSize = 32;

constructor(entropyOrPrivate, sourceType = 'entropy') {
let kp;
switch (sourceType) {
case 'entropy':
if (entropyOrPrivate == null) {
throw new Error('Entropy must be provided');
}

kp = secp256r1Curve.genKeyPair({
entropy: entropyOrPrivate,
});
break;
case 'private':
kp = secp256r1Curve.keyFromPrivate(normalizeToU8a(entropyOrPrivate));
break;
default:
throw new Error(
`Unknown source type: \`${sourceType}\`, it must be either "entropy" or "private"`,
);
}

super(kp);
}

_publicKey() {
return hexToU8a(`0x${this.keyPair.getPublic(true, 'hex')}`);
}

privateKey() {
return hexToU8a(`0x${this.keyPair.getPrivate('hex')}`);
}

_sign(message) {
const hash = this.constructor.hash(message);
const sig = this.keyPair.sign(hash, {
canonical: true,
});

const r = sig.r.toString('hex', 32);
const s = sig.s.toString('hex', 32);
const i = sig.recoveryParam.toString(16).padStart(2, '0');

return hexToU8a(`0x${r}${s}${i}`);
}

static signatureToDER(signature) {
const sigBytes = valueBytes(signature);
if (sigBytes.length !== 65) {
throw new Error(
`Invalid signature length. Expected is 65 bytes, received ${sigBytes.length}`,
);
}

const r = sigBytes.slice(0, 32);
const s = sigBytes.slice(32, 64);

const rEncoded = encodeDERInt(r);
const sEncoded = encodeDERInt(s);

const totalLength = rEncoded.length + sEncoded.length;

const der = new Uint8Array(2 + totalLength);
der[0] = 0x30;
der[1] = totalLength;

der.set(rEncoded, 2);
der.set(sEncoded, 2 + rEncoded.length);

return der;
}

static hash(message) {
return sha256.digest(message);
}

static verify(message, signature, publicKey) {
let bytes = valueBytes(signature);
if (bytes.length === 65) {
bytes = this.signatureToDER(bytes);
}

return secp256r1Curve.verify(
this.hash(message),
bytes,
valueBytes(publicKey),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TypedEnum, Null } from '../../generic';
import {
EcdsaSecp256k1VerKeyName,
EcdsaSecp256r1VerKeyName,
Ed255192020VerKeyName,
Ed25519VerKeyName,
Sr25519VerKeyName,
Expand Down Expand Up @@ -37,6 +38,11 @@ export class EcdsaSecp256k1VerificationKey2019 extends VerificationMethodType {

static Type = EcdsaSecp256k1VerKeyName;
}
export class EcdsaSecp256r1VerificationKey2019 extends VerificationMethodType {
static Class = Null;

static Type = EcdsaSecp256r1VerKeyName;
}
export class X25519KeyAgreementKey2019 extends VerificationMethodType {
static Class = Null;

Expand Down Expand Up @@ -67,6 +73,7 @@ VerificationMethodType.bindVariants(
Ed25519Verification2020Method,
Sr25519Verification2020Method,
EcdsaSecp256k1VerificationKey2019,
EcdsaSecp256r1VerificationKey2019,
X25519KeyAgreementKey2019,
Bls12381G2VerificationKeyDock2022,
Bls12381BBSVerificationKeyDock2023,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import {
import {
PublicKeyEd25519,
PublicKeySecp256k1,
PublicKeySecp256r1,
PublicKeySr25519,
} from '../../public-keys';
import {
EcdsaSecp256k1VerKeyName,
EcdsaSecp256r1VerKeyName,
Ed255192020VerKeyName,
Ed25519VerKeyName,
Sr25519VerKeyName,
Expand Down Expand Up @@ -233,6 +235,8 @@ export class VerificationMethod extends withFrom(
return PublicKeyEd25519;
case EcdsaSecp256k1VerKeyName:
return PublicKeySecp256k1;
case EcdsaSecp256r1VerKeyName:
return PublicKeySecp256r1;
case Bls12381BBSDockVerKeyName:
return BBSPlusPublicKey;
case Bls12381BBS23DockVerKeyName:
Expand Down
4 changes: 4 additions & 0 deletions packages/credential-sdk/src/types/did/onchain/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const DockDIDMethod = 'dock';
export const CheqdDIDMethod = 'cheqd';
export const Secp256k1PublicKeyPrefix = 'zQ3s';
export const Secp256r1PublicKeyPrefix = 'zDn';
export const Ed25519PublicKeyPrefix = 'z6Mk';
export const BBS23PublicKeyPrefix = 'zVMC';
export const BBSPlusPublicKeyPrefix = 'zVTu';
Expand All @@ -15,16 +16,19 @@ export const CheqdDIDByteSize = 16;

export const DidMethodKeyQualifier = 'did:key:';
export const DidMethodKeySecp256k1ByteSize = 33;
export const DidMethodKeySecp256r1ByteSize = 33;
export const DidMethodKeyEd25519ByteSize = 32;
export const DidMethodKeyBBS23ByteSize = 96;
export const DidMethodKeyBBSPlusByteSize = 96;

export const DidMethodKeySecp256k1Prefix = `${DidMethodKeyQualifier}${Secp256k1PublicKeyPrefix}`;
export const DidMethodKeySecp256r1Prefix = `${DidMethodKeyQualifier}${Secp256r1PublicKeyPrefix}`;
export const DidMethodKeyEd25519Prefix = `${DidMethodKeyQualifier}${Ed25519PublicKeyPrefix}`;
export const DidMethodKeyBBS23Prefix = `${DidMethodKeyQualifier}${BBS23PublicKeyPrefix}`;
export const DidMethodKeyBBSPlusPrefix = `${DidMethodKeyQualifier}${BBSPlusPublicKeyPrefix}`;

export const DidMethodKeyBytePrefixEd25519 = new Uint8Array([0xed, 0x01]);
export const DidMethodKeyBytePrefixSecp256k1 = new Uint8Array([0xe7, 0x01]);
export const DidMethodKeyBytePrefixSecp256r1 = new Uint8Array([0x80, 0x24]);
export const DidMethodKeyBytePrefixBBS23 = new Uint8Array([0xf5, 0x01]);
export const DidMethodKeyBytePrefixBBSPlus = new Uint8Array([0xf6, 0x01]);
8 changes: 8 additions & 0 deletions packages/credential-sdk/src/types/did/onchain/did-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
import {
PublicKeyEd25519Value,
PublicKeySecp256k1Value,
PublicKeySecp256r1Value,
PublicKeySr25519Value,
PublicKeyX25519Value,
} from '../../public-keys';
Expand Down Expand Up @@ -51,6 +52,11 @@ export class DidKeySecp256k1PublicKey extends DidKeyValue {

static Class = PublicKeySecp256k1Value;
}
export class DidKeySecp256r1PublicKey extends DidKeyValue {
static Type = 'secp256r1';

static Class = PublicKeySecp256r1Value;
}
/**
* Class representing Sr25519 PublicKey
* @class
Expand Down Expand Up @@ -96,6 +102,7 @@ export class DidKeyPSPublicKey extends DidKeyValue {
DidKeyValue.bindVariants(
DidKeyEd25519PublicKey,
DidKeySecp256k1PublicKey,
DidKeySecp256r1PublicKey,
DidKeySr25519PublicKey,
DidKeyX25519PublicKey,
DidKeyBBSPublicKey,
Expand All @@ -107,6 +114,7 @@ const Signing = [
DidKeyEd25519PublicKey,
DidKeySr25519PublicKey,
DidKeySecp256k1PublicKey,
DidKeySecp256r1PublicKey,
];

const Assertion = [
Expand Down
Loading
Loading