Comparing version 5.7.0 to 5.8.0
var u8a = require('uint8arrays'); | ||
var basics = require('multiformats/basics'); | ||
var sha256$1 = require('@stablelib/sha256'); | ||
@@ -398,2 +399,11 @@ var jsSha3 = require('js-sha3'); | ||
}).getPublic('hex')); | ||
} else if (pk.publicKeyMultibase) { | ||
const { | ||
base16, | ||
base58btc, | ||
base64, | ||
base64url | ||
} = basics.bases; | ||
const baseDecoder = base16.decoder.or(base58btc.decoder.or(base64.decoder.or(base64url.decoder))); | ||
return baseDecoder.decode(pk.publicKeyMultibase); | ||
} | ||
@@ -400,0 +410,0 @@ |
import * as u8a from 'uint8arrays'; | ||
import { bases } from 'multiformats/basics'; | ||
import { hash } from '@stablelib/sha256'; | ||
@@ -372,2 +373,11 @@ import { keccak_256 } from 'js-sha3'; | ||
}).getPublic('hex')); | ||
} else if (pk.publicKeyMultibase) { | ||
const { | ||
base16, | ||
base58btc, | ||
base64, | ||
base64url | ||
} = bases; | ||
const baseDecoder = base16.decoder.or(base58btc.decoder.or(base64.decoder.or(base64url.decoder))); | ||
return baseDecoder.decode(pk.publicKeyMultibase); | ||
} | ||
@@ -374,0 +384,0 @@ |
import * as u8a from 'uint8arrays'; | ||
import { bases } from 'multiformats/basics'; | ||
import { hash } from '@stablelib/sha256'; | ||
@@ -373,2 +374,11 @@ import { keccak_256 } from 'js-sha3'; | ||
}).getPublic('hex')); | ||
} else if (pk.publicKeyMultibase) { | ||
const { | ||
base16, | ||
base58btc, | ||
base64, | ||
base64url | ||
} = bases; | ||
const baseDecoder = base16.decoder.or(base58btc.decoder.or(base64.decoder.or(base64url.decoder))); | ||
return baseDecoder.decode(pk.publicKeyMultibase); | ||
} | ||
@@ -375,0 +385,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { bases } from 'multiformats/basics'; | ||
/** | ||
@@ -14,2 +15,3 @@ * @deprecated Signers will be expected to return base64url `string` signatures. | ||
export declare function bytesToBase58(b: Uint8Array): string; | ||
export declare function bytesToMultibase(b: Uint8Array, base: keyof typeof bases): string; | ||
export declare function hexToBytes(s: string): Uint8Array; | ||
@@ -16,0 +18,0 @@ export declare function encodeBase64url(s: string): string; |
{ | ||
"name": "did-jwt", | ||
"version": "5.7.0", | ||
"version": "5.8.0", | ||
"description": "Library for Signing and Verifying JWTs that use DIDs as issuers and JWEs that use DIDs as recipients", | ||
@@ -67,3 +67,3 @@ "source": "src/index.ts", | ||
"eslint-plugin-jest": "24.3.6", | ||
"eslint-plugin-prettier": "3.4.0", | ||
"eslint-plugin-prettier": "4.0.0", | ||
"jest": "27.0.5", | ||
@@ -88,5 +88,6 @@ "jsontokens": "3.0.0", | ||
"canonicalize": "^1.0.5", | ||
"did-resolver": "^3.1.0", | ||
"did-resolver": "^3.1.1", | ||
"elliptic": "^6.5.4", | ||
"js-sha3": "^0.8.0", | ||
"multiformats": "^9.4.8", | ||
"uint8arrays": "^3.0.0" | ||
@@ -93,0 +94,0 @@ }, |
@@ -6,3 +6,3 @@ import VerifierAlgorithm from '../VerifierAlgorithm' | ||
import { ec as EC } from 'elliptic' | ||
import { base64ToBytes, bytesToBase58, bytesToBase64, hexToBytes, bytesToBase64url } from '../util' | ||
import { base64ToBytes, bytesToBase58, bytesToBase64, hexToBytes, bytesToBase64url, bytesToMultibase } from '../util' | ||
import * as u8a from 'uint8arrays' | ||
@@ -46,2 +46,3 @@ import { EdDSASigner } from '../signers/EdDSASigner' | ||
} | ||
const publicKeyMultibase = bytesToMultibase(hexToBytes(publicKey), 'base58btc') | ||
const address = toEthereumAddress(publicKey) | ||
@@ -174,2 +175,11 @@ const signer = ES256KSigner(privateKey) | ||
it('validates with publicKeyMultibase', async () => { | ||
expect.assertions(1) | ||
const jwt = await createJWT({ bla: 'bla' }, { issuer: did, signer }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
const pubkey = Object.assign({ publicKeyMultibase }, ecKey2) | ||
delete pubkey.publicKeyHex | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
}) | ||
it('validates signature with compressed public key and picks correct public key', async () => { | ||
@@ -293,2 +303,11 @@ expect.assertions(1) | ||
it('validates with publicKeyMultibase', async () => { | ||
expect.assertions(1) | ||
const jwt = await createJWT({ bla: 'bla' }, { issuer: did, signer: recoverySigner, alg: 'ES256K-R' }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
const pubkey = Object.assign({ publicKeyMultibase }, ecKey2) | ||
delete pubkey.publicKeyHex | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
}) | ||
it('throws error if invalid signature', async () => { | ||
@@ -295,0 +314,0 @@ expect.assertions(1) |
import * as u8a from 'uint8arrays' | ||
import { bases } from 'multiformats/basics' | ||
@@ -33,2 +34,6 @@ /** | ||
export function bytesToMultibase(b: Uint8Array, base: keyof typeof bases): string { | ||
return bases[base].encode(b) | ||
} | ||
export function hexToBytes(s: string): Uint8Array { | ||
@@ -35,0 +40,0 @@ const input = s.startsWith('0x') ? s.substring(2) : s |
@@ -5,2 +5,3 @@ import { ec as EC, SignatureInput } from 'elliptic' | ||
import type { VerificationMethod } from 'did-resolver' | ||
import { bases } from 'multiformats/basics' | ||
import { hexToBytes, base58ToBytes, base64ToBytes, bytesToHex, EcdsaSignature, stringToBytes } from './util' | ||
@@ -45,2 +46,6 @@ | ||
) | ||
} else if (pk.publicKeyMultibase) { | ||
const { base16, base58btc, base64, base64url } = bases | ||
const baseDecoder = base16.decoder.or(base58btc.decoder.or(base64.decoder.or(base64url.decoder))) | ||
return baseDecoder.decode(pk.publicKeyMultibase) | ||
} | ||
@@ -47,0 +52,0 @@ return new Uint8Array() |
@@ -6,3 +6,3 @@ import { XChaCha20Poly1305 } from '@stablelib/xchacha20poly1305' | ||
import { bytesToBase64url, base58ToBytes, encodeBase64url, toSealed, base64ToBytes } from './util' | ||
import { Recipient, EncryptionResult, Encrypter, Decrypter, RecipientHeader, ProtectedHeader } from './JWE' | ||
import { Recipient, EncryptionResult, Encrypter, Decrypter, ProtectedHeader } from './JWE' | ||
import type { VerificationMethod, Resolvable } from 'did-resolver' | ||
@@ -9,0 +9,0 @@ import { ECDH } from './ECDH' |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1120492
10397
11
+ Addedmultiformats@^9.4.8
Updateddid-resolver@^3.1.1