Skip to content

Commit e15adb9

Browse files
authored
fix(deps): Update dependency did-jwt to v7.4.5 (#142)
fixes #135
1 parent da31172 commit e15adb9

File tree

5 files changed

+1012
-1531
lines changed

5 files changed

+1012
-1531
lines changed

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
],
3636
"license": "ISC",
3737
"dependencies": {
38-
"did-jwt": "^7.4.1",
38+
"did-jwt": "^7.4.5",
3939
"did-resolver": "^4.1.0"
4040
},
4141
"repository": {
@@ -46,25 +46,26 @@
4646
"@babel/core": "7.23.2",
4747
"@babel/preset-env": "7.23.2",
4848
"@babel/preset-typescript": "7.23.2",
49+
"@noble/curves": "1.2.0",
4950
"@semantic-release/changelog": "6.0.3",
5051
"@semantic-release/git": "10.0.1",
5152
"@types/elliptic": "6.4.16",
5253
"@types/faker": "6.6.9",
53-
"@types/jest": "29.5.6",
54-
"@types/node": "20.8.9",
55-
"@typescript-eslint/eslint-plugin": "5.62.0",
56-
"@typescript-eslint/parser": "5.62.0",
54+
"@types/jest": "29.5.7",
55+
"@types/node": "20.8.10",
56+
"@typescript-eslint/eslint-plugin": "6.9.1",
57+
"@typescript-eslint/parser": "6.9.1",
5758
"cross-env": "7.0.3",
5859
"eslint": "8.52.0",
59-
"eslint-config-prettier": "8.10.0",
60+
"eslint-config-prettier": "9.0.0",
6061
"eslint-plugin-jest": "27.6.0",
61-
"eslint-plugin-prettier": "4.2.1",
62-
"ethr-did": "2.3.23",
62+
"eslint-plugin-prettier": "5.0.1",
63+
"ethr-did": "3.0.3",
6364
"faker": "6.6.6",
6465
"jest": "29.7.0",
6566
"microbundle": "0.15.1",
66-
"prettier": "2.8.8",
67-
"semantic-release": "21.1.2",
67+
"prettier": "3.0.3",
68+
"semantic-release": "22.0.6",
6869
"ts-jest": "29.1.1",
6970
"typescript": "5.2.2"
7071
},

src/__tests__/converters.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {
99
import { DEFAULT_JWT_PROOF_TYPE } from '../types'
1010
import { CredentialPayload, PresentationPayload } from '../types'
1111
import { validateJwtCredentialPayload, validateJwtPresentationPayload } from '..'
12+
import { bytesToBase64url } from 'did-jwt'
13+
import { utf8ToBytes } from '@noble/curves/abstract/utils'
1214

13-
import * as u8a from 'uint8arrays'
14-
15-
function encodeBase64Url(input: string): string {
16-
return u8a.toString(u8a.fromString(input, 'utf-8'), 'base64url')
15+
function encodeBase64url(s: string): string {
16+
return bytesToBase64url(utf8ToBytes(s))
1717
}
1818

1919
describe('credential', () => {
@@ -602,7 +602,7 @@ describe('credential', () => {
602602
const payload = JSON.stringify(complexInput)
603603
const header = '{}'
604604

605-
const credential = `${encodeBase64Url(header)}.${encodeBase64Url(payload)}.signature`
605+
const credential = `${encodeBase64url(header)}.${encodeBase64url(payload)}.signature`
606606

607607
const result = normalizeCredential(credential)
608608

@@ -622,7 +622,7 @@ describe('credential', () => {
622622
const payload = JSON.stringify(complexInput)
623623
const header = '{}'
624624

625-
const credential = `${encodeBase64Url(header)}.${encodeBase64Url(payload)}.signature`
625+
const credential = `${encodeBase64url(header)}.${encodeBase64url(payload)}.signature`
626626

627627
const result = normalizeCredential(credential, false)
628628

src/__tests__/index.test.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { EthrDID } from 'ethr-did'
22
import type { Issuer, JwtCredentialPayload } from '../index.js'
3-
43
import {
54
createVerifiableCredentialJwt,
65
createVerifiablePresentationJwt,
@@ -9,7 +8,7 @@ import {
98
verifyPresentationPayloadOptions,
109
} from '../index.js'
1110

12-
import { decodeJWT, ES256KSigner, hexToBytes } from 'did-jwt'
11+
import { bytesToBase64url, decodeJWT, ES256KSigner, hexToBytes } from 'did-jwt'
1312
import type { Resolvable } from 'did-resolver'
1413
import {
1514
type CreatePresentationOptions,
@@ -18,14 +17,10 @@ import {
1817
DEFAULT_VP_TYPE,
1918
type VerifyPresentationOptions,
2019
} from '../types.js'
21-
22-
import elliptic from 'elliptic'
23-
import * as u8a from 'uint8arrays'
20+
import { secp256k1 } from '@noble/curves/secp256k1'
2421

2522
import { jest } from '@jest/globals'
2623

27-
const secp256k1 = new elliptic.ec('secp256k1')
28-
2924
const DID_B = 'did:ethr:0x435df3eda57154cf8cf7926079881f2912f54db4'
3025
const EXTRA_CONTEXT_A = 'https://www.w3.org/2018/credentials/examples/v1'
3126
const EXTRA_TYPE_A = 'UniversityDegreeCredential'
@@ -375,12 +370,13 @@ describe('github #98', () => {
375370
it('verifies a JWT issued by a DID with publicKeyJwk', async () => {
376371
const did = `did:ion:long-form-mock`
377372
const privateKeyHex = '278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f'
378-
const pubKey = secp256k1.keyFromPrivate(privateKeyHex, 'hex').getPublic()
373+
const pubKeyBytes = secp256k1.getPublicKey(privateKeyHex, false)
374+
const point = secp256k1.ProjectivePoint.fromHex(pubKeyBytes).toAffine()
379375
const publicKeyJwk = {
380376
kty: 'EC',
381377
crv: 'secp256k1',
382-
x: u8a.toString(pubKey.getX().toBuffer(), 'base64url'),
383-
y: u8a.toString(pubKey.getY().toBuffer(), 'base64url'),
378+
x: bytesToBase64url(hexToBytes(point.x.toString(16))),
379+
y: bytesToBase64url(hexToBytes(point.y.toString(16))),
384380
}
385381

386382
const localResolver: Resolvable = {

src/converters.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@ function deepCopy<T>(source: T): T {
3434
: source instanceof Date
3535
? new Date(source.getTime())
3636
: source && typeof source === 'object'
37-
? Object.getOwnPropertyNames(source).reduce((o, prop) => {
38-
Object.defineProperty(o, prop, Object.getOwnPropertyDescriptor(source, prop) as NonNullable<PropertyDescriptor>)
39-
o[prop] = deepCopy(source[prop as keyof T])
40-
return o
41-
}, Object.create(Object.getPrototypeOf(source)))
37+
? Object.getOwnPropertyNames(source).reduce(
38+
(o, prop) => {
39+
Object.defineProperty(
40+
o,
41+
prop,
42+
Object.getOwnPropertyDescriptor(source, prop) as NonNullable<PropertyDescriptor>
43+
)
44+
o[prop] = deepCopy(source[prop as keyof T])
45+
return o
46+
},
47+
Object.create(Object.getPrototypeOf(source))
48+
)
4249
: (source as T)
4350
}
4451

0 commit comments

Comments
 (0)