Skip to content

Commit

Permalink
fix(deps): Update dependency did-jwt to v7.4.5 (#142)
Browse files Browse the repository at this point in the history
fixes #135
  • Loading branch information
mirceanis authored Nov 1, 2023
1 parent da31172 commit e15adb9
Show file tree
Hide file tree
Showing 5 changed files with 1,012 additions and 1,531 deletions.
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
],
"license": "ISC",
"dependencies": {
"did-jwt": "^7.4.1",
"did-jwt": "^7.4.5",
"did-resolver": "^4.1.0"
},
"repository": {
Expand All @@ -46,25 +46,26 @@
"@babel/core": "7.23.2",
"@babel/preset-env": "7.23.2",
"@babel/preset-typescript": "7.23.2",
"@noble/curves": "1.2.0",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/git": "10.0.1",
"@types/elliptic": "6.4.16",
"@types/faker": "6.6.9",
"@types/jest": "29.5.6",
"@types/node": "20.8.9",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"@types/jest": "29.5.7",
"@types/node": "20.8.10",
"@typescript-eslint/eslint-plugin": "6.9.1",
"@typescript-eslint/parser": "6.9.1",
"cross-env": "7.0.3",
"eslint": "8.52.0",
"eslint-config-prettier": "8.10.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-jest": "27.6.0",
"eslint-plugin-prettier": "4.2.1",
"ethr-did": "2.3.23",
"eslint-plugin-prettier": "5.0.1",
"ethr-did": "3.0.3",
"faker": "6.6.6",
"jest": "29.7.0",
"microbundle": "0.15.1",
"prettier": "2.8.8",
"semantic-release": "21.1.2",
"prettier": "3.0.3",
"semantic-release": "22.0.6",
"ts-jest": "29.1.1",
"typescript": "5.2.2"
},
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/converters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
import { DEFAULT_JWT_PROOF_TYPE } from '../types'
import { CredentialPayload, PresentationPayload } from '../types'
import { validateJwtCredentialPayload, validateJwtPresentationPayload } from '..'
import { bytesToBase64url } from 'did-jwt'
import { utf8ToBytes } from '@noble/curves/abstract/utils'

import * as u8a from 'uint8arrays'

function encodeBase64Url(input: string): string {
return u8a.toString(u8a.fromString(input, 'utf-8'), 'base64url')
function encodeBase64url(s: string): string {
return bytesToBase64url(utf8ToBytes(s))
}

describe('credential', () => {
Expand Down Expand Up @@ -602,7 +602,7 @@ describe('credential', () => {
const payload = JSON.stringify(complexInput)
const header = '{}'

const credential = `${encodeBase64Url(header)}.${encodeBase64Url(payload)}.signature`
const credential = `${encodeBase64url(header)}.${encodeBase64url(payload)}.signature`

const result = normalizeCredential(credential)

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

const credential = `${encodeBase64Url(header)}.${encodeBase64Url(payload)}.signature`
const credential = `${encodeBase64url(header)}.${encodeBase64url(payload)}.signature`

const result = normalizeCredential(credential, false)

Expand Down
16 changes: 6 additions & 10 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EthrDID } from 'ethr-did'
import type { Issuer, JwtCredentialPayload } from '../index.js'

import {
createVerifiableCredentialJwt,
createVerifiablePresentationJwt,
Expand All @@ -9,7 +8,7 @@ import {
verifyPresentationPayloadOptions,
} from '../index.js'

import { decodeJWT, ES256KSigner, hexToBytes } from 'did-jwt'
import { bytesToBase64url, decodeJWT, ES256KSigner, hexToBytes } from 'did-jwt'
import type { Resolvable } from 'did-resolver'
import {
type CreatePresentationOptions,
Expand All @@ -18,14 +17,10 @@ import {
DEFAULT_VP_TYPE,
type VerifyPresentationOptions,
} from '../types.js'

import elliptic from 'elliptic'
import * as u8a from 'uint8arrays'
import { secp256k1 } from '@noble/curves/secp256k1'

import { jest } from '@jest/globals'

const secp256k1 = new elliptic.ec('secp256k1')

const DID_B = 'did:ethr:0x435df3eda57154cf8cf7926079881f2912f54db4'
const EXTRA_CONTEXT_A = 'https://www.w3.org/2018/credentials/examples/v1'
const EXTRA_TYPE_A = 'UniversityDegreeCredential'
Expand Down Expand Up @@ -375,12 +370,13 @@ describe('github #98', () => {
it('verifies a JWT issued by a DID with publicKeyJwk', async () => {
const did = `did:ion:long-form-mock`
const privateKeyHex = '278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f'
const pubKey = secp256k1.keyFromPrivate(privateKeyHex, 'hex').getPublic()
const pubKeyBytes = secp256k1.getPublicKey(privateKeyHex, false)
const point = secp256k1.ProjectivePoint.fromHex(pubKeyBytes).toAffine()
const publicKeyJwk = {
kty: 'EC',
crv: 'secp256k1',
x: u8a.toString(pubKey.getX().toBuffer(), 'base64url'),
y: u8a.toString(pubKey.getY().toBuffer(), 'base64url'),
x: bytesToBase64url(hexToBytes(point.x.toString(16))),
y: bytesToBase64url(hexToBytes(point.y.toString(16))),
}

const localResolver: Resolvable = {
Expand Down
17 changes: 12 additions & 5 deletions src/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ function deepCopy<T>(source: T): T {
: source instanceof Date
? new Date(source.getTime())
: source && typeof source === 'object'
? Object.getOwnPropertyNames(source).reduce((o, prop) => {
Object.defineProperty(o, prop, Object.getOwnPropertyDescriptor(source, prop) as NonNullable<PropertyDescriptor>)
o[prop] = deepCopy(source[prop as keyof T])
return o
}, Object.create(Object.getPrototypeOf(source)))
? Object.getOwnPropertyNames(source).reduce(
(o, prop) => {
Object.defineProperty(
o,
prop,
Object.getOwnPropertyDescriptor(source, prop) as NonNullable<PropertyDescriptor>
)
o[prop] = deepCopy(source[prop as keyof T])
return o
},
Object.create(Object.getPrototypeOf(source))
)
: (source as T)
}

Expand Down
Loading

0 comments on commit e15adb9

Please sign in to comment.