Comparing version 6.11.6 to 6.11.7-alpha.1
export declare const publicKeyToAddress: (publicKey: string, otherAddress: string) => string; | ||
//# sourceMappingURL=bip122.d.ts.map |
export declare const publicKeyToAddress: (publicKey: string, prefix: string) => string; | ||
//# sourceMappingURL=cosmos.d.ts.map |
export declare const verifyBlockchainAccountId: (publicKey: string, blockchainAccountId: string | undefined) => boolean; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,0 +0,0 @@ export declare class Ripemd160 { |
@@ -0,0 +0,0 @@ export declare function sha256(payload: string | Uint8Array): Uint8Array; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -1,16 +0,16 @@ | ||
import SimpleSigner from './signers/SimpleSigner'; | ||
import EllipticSigner from './signers/EllipticSigner'; | ||
import NaclSigner from './signers/NaclSigner'; | ||
import { ES256KSigner } from './signers/ES256KSigner'; | ||
import { ES256Signer } from './signers/ES256Signer'; | ||
import { EdDSASigner } from './signers/EdDSASigner'; | ||
import { createJWS, createJWT, decodeJWT, JWTHeader, JWTPayload, JWTVerified, Signer, verifyJWS, verifyJWT } from './JWT'; | ||
import { toEthereumAddress } from './Digest'; | ||
export { JWE, createJWE, decryptJWE, Encrypter, Decrypter, ProtectedHeader, Recipient, RecipientHeader } from './JWE'; | ||
export { ECDH, createX25519ECDH } from './ECDH'; | ||
export { xc20pDirEncrypter, xc20pDirDecrypter, x25519Encrypter, x25519Decrypter, resolveX25519Encrypters, createAuthEncrypter, createAnonEncrypter, createAuthDecrypter, createAnonDecrypter, xc20pAuthEncrypterEcdh1PuV3x25519WithXc20PkwV2, xc20pAuthDecrypterEcdh1PuV3x25519WithXc20PkwV2, } from './xc20pEncryption'; | ||
export { SimpleSigner, EllipticSigner, NaclSigner, ES256Signer, ES256KSigner, EdDSASigner, verifyJWT, createJWT, decodeJWT, verifyJWS, createJWS, toEthereumAddress, Signer, JWTHeader, JWTPayload, JWTVerified, }; | ||
export { JWTOptions, JWTVerifyOptions } from './JWT'; | ||
export { base64ToBytes, base58ToBytes, hexToBytes } from './util'; | ||
export * from './Errors'; | ||
import SimpleSigner from './signers/SimpleSigner.js'; | ||
import EllipticSigner from './signers/EllipticSigner.js'; | ||
import NaclSigner from './signers/NaclSigner.js'; | ||
import { ES256KSigner } from './signers/ES256KSigner.js'; | ||
import { ES256Signer } from './signers/ES256Signer.js'; | ||
import { EdDSASigner } from './signers/EdDSASigner.js'; | ||
import { createJWS, createJWT, decodeJWT, type JWTHeader, type JWTPayload, type JWTVerified, type Signer, verifyJWS, verifyJWT } from './JWT.js'; | ||
import { toEthereumAddress } from './Digest.js'; | ||
export { type JWE, createJWE, decryptJWE, type Encrypter, type Decrypter, type ProtectedHeader, type Recipient, type RecipientHeader, } from './JWE.js'; | ||
export { type ECDH, createX25519ECDH } from './ECDH.js'; | ||
export { xc20pDirEncrypter, xc20pDirDecrypter, x25519Encrypter, x25519Decrypter, resolveX25519Encrypters, createAuthEncrypter, createAnonEncrypter, createAuthDecrypter, createAnonDecrypter, xc20pAuthEncrypterEcdh1PuV3x25519WithXc20PkwV2, xc20pAuthDecrypterEcdh1PuV3x25519WithXc20PkwV2, } from './xc20pEncryption.js'; | ||
export { SimpleSigner, EllipticSigner, NaclSigner, ES256Signer, ES256KSigner, EdDSASigner, verifyJWT, createJWT, decodeJWT, verifyJWS, createJWS, toEthereumAddress, type Signer, type JWTHeader, type JWTPayload, type JWTVerified, }; | ||
export { type JWTOptions, type JWTVerifyOptions } from './JWT.js'; | ||
export { base64ToBytes, base58ToBytes, hexToBytes } from './util.js'; | ||
export * from './Errors.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,0 +0,0 @@ export type ProtectedHeader = Record<string, any> & Partial<RecipientHeader>; |
import type { DIDResolutionResult, Resolvable, VerificationMethod } from 'did-resolver'; | ||
import { EcdsaSignature } from './util'; | ||
import { EcdsaSignature } from './util.js'; | ||
export type Signer = (data: string | Uint8Array) => Promise<EcdsaSignature | string>; | ||
@@ -4,0 +4,0 @@ export type SignerAlgorithm = (payload: string, signer: Signer) => Promise<string>; |
@@ -1,2 +0,2 @@ | ||
import { SignerAlgorithm } from './JWT'; | ||
import type { SignerAlgorithm } from './JWT.js'; | ||
export declare function ES256SignerAlg(): SignerAlgorithm; | ||
@@ -3,0 +3,0 @@ export declare function ES256KSignerAlg(recoverable?: boolean): SignerAlgorithm; |
@@ -1,2 +0,2 @@ | ||
import { Signer } from '../JWT'; | ||
import type { Signer } from '../JWT.js'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Creates a configured signer function for signing data using the EdDSA (Ed25519) algorithm. |
@@ -1,2 +0,2 @@ | ||
import { Signer } from '../JWT'; | ||
import type { Signer } from '../JWT.js'; | ||
/** | ||
@@ -3,0 +3,0 @@ * @deprecated Please use ES256KSigner |
@@ -1,2 +0,2 @@ | ||
import { Signer } from '../JWT'; | ||
import type { Signer } from '../JWT.js'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Creates a configured signer function for signing data using the ES256K (secp256k1 + sha256) algorithm. |
@@ -1,2 +0,2 @@ | ||
import { Signer } from '../JWT'; | ||
import type { Signer } from '../JWT.js'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Creates a configured signer function for signing data using the ES256 (secp256r1 + sha256) algorithm. |
@@ -1,2 +0,2 @@ | ||
import { Signer } from '../JWT'; | ||
import type { Signer } from '../JWT.js'; | ||
/** | ||
@@ -7,3 +7,4 @@ * @deprecated Please use EdDSASigner | ||
* | ||
* The signing function itself takes the data as a `string` or `Uint8Array` parameter and returns a `base64Url`-encoded signature. | ||
* The signing function itself takes the data as a `string` or `Uint8Array` parameter and returns a | ||
* `base64Url`-encoded signature. | ||
* | ||
@@ -10,0 +11,0 @@ * @example |
@@ -1,2 +0,2 @@ | ||
import { Signer } from '../JWT'; | ||
import type { Signer } from '../JWT.js'; | ||
/** | ||
@@ -3,0 +3,0 @@ * @deprecated Please use ES256KSigner |
@@ -8,3 +8,3 @@ import { bases } from 'multiformats/basics'; | ||
s: string; | ||
recoveryParam?: number | null; | ||
recoveryParam?: number; | ||
} | ||
@@ -11,0 +11,0 @@ export declare function bytesToBase64url(b: Uint8Array): string; |
import type { VerificationMethod } from 'did-resolver'; | ||
import { EcdsaSignature } from './util'; | ||
import { EcdsaSignature } from './util.js'; | ||
export declare function toSignatureObject(signature: string, recoverable?: boolean): EcdsaSignature; | ||
@@ -11,5 +11,5 @@ export declare function verifyES256(data: string, signature: string, authenticators: VerificationMethod[]): VerificationMethod; | ||
declare namespace VerifierAlgorithm { | ||
var toSignatureObject: typeof import("./VerifierAlgorithm").toSignatureObject; | ||
var toSignatureObject: typeof import("./VerifierAlgorithm.js").toSignatureObject; | ||
} | ||
export default VerifierAlgorithm; | ||
//# sourceMappingURL=VerifierAlgorithm.d.ts.map |
@@ -1,4 +0,4 @@ | ||
import { Encrypter, Decrypter } from './JWE'; | ||
import type { Resolvable } from 'did-resolver'; | ||
import { ECDH } from './ECDH'; | ||
import { Decrypter, Encrypter } from './JWE.js'; | ||
import { ECDH } from './ECDH.js'; | ||
/** | ||
@@ -5,0 +5,0 @@ * Extra parameters for JWE using authenticated encryption |
{ | ||
"name": "did-jwt", | ||
"version": "6.11.6", | ||
"version": "6.11.7-alpha.1", | ||
"description": "Library for Signing and Verifying JWTs that use DIDs as issuers and JWEs that use DIDs as recipients", | ||
@@ -9,5 +9,3 @@ "type": "module", | ||
"module": "./lib/index.module.js", | ||
"unpkg": "./lib/index.umd.js", | ||
"types": "./lib/index.d.ts", | ||
"umd:main": "./lib/index.umd.js", | ||
"files": [ | ||
@@ -26,5 +24,6 @@ "lib", | ||
}, | ||
"browser": "./dist/did-jwt.js", | ||
"scripts": { | ||
"test": "jest", | ||
"test:ci": "jest --coverage", | ||
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest", | ||
"test:ci": "yarn test --coverage", | ||
"build:js": "microbundle --compress=false", | ||
@@ -42,3 +41,3 @@ "build:browser": "webpack --config webpack.config.cjs", | ||
"Mircea Nistor <mircea.nistor@mesh.xyz>", | ||
"Oliver Terbu <oliver.terbu@mesh.xyz>", | ||
"Oliver Terbu", | ||
"Joel Thorstensson <oed@3box.io>" | ||
@@ -51,15 +50,2 @@ ], | ||
"license": "Apache-2.0", | ||
"jest": { | ||
"clearMocks": true, | ||
"collectCoverageFrom": [ | ||
"src/**/*.{ts,tsx}", | ||
"!src/**/*.d.ts", | ||
"!**/node_modules/**", | ||
"!src/**/index.ts" | ||
], | ||
"testEnvironment": "node", | ||
"testMatch": [ | ||
"**/__tests__/**/*.test.[jt]s" | ||
] | ||
}, | ||
"devDependencies": { | ||
@@ -73,16 +59,17 @@ "@babel/core": "7.21.3", | ||
"@types/elliptic": "6.4.14", | ||
"@types/jest": "28.1.8", | ||
"@types/jsonwebtoken": "^8.5.9", | ||
"@types/jwk-to-pem": "^2.0.1", | ||
"@typescript-eslint/eslint-plugin": "5.56.0", | ||
"@typescript-eslint/parser": "5.56.0", | ||
"@types/jest": "29.5.0", | ||
"@types/jsonwebtoken": "9.0.1", | ||
"@types/jwk-to-pem": "2.0.1", | ||
"@typescript-eslint/eslint-plugin": "5.57.0", | ||
"@typescript-eslint/parser": "5.57.0", | ||
"codecov": "3.8.3", | ||
"eslint": "8.36.0", | ||
"cross-env": "7.0.3", | ||
"eslint": "8.37.0", | ||
"eslint-config-prettier": "8.8.0", | ||
"eslint-plugin-jest": "26.9.0", | ||
"eslint-plugin-jest": "27.2.1", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"jest": "28.1.3", | ||
"jsontokens": "3.1.1", | ||
"jsonwebtoken": "^8.5.1", | ||
"jwk-to-pem": "^2.0.5", | ||
"jest": "29.5.0", | ||
"jsontokens": "4.0.1", | ||
"jsonwebtoken": "9.0.0", | ||
"jwk-to-pem": "2.0.5", | ||
"microbundle": "0.15.1", | ||
@@ -92,21 +79,23 @@ "mockdate": "3.0.5", | ||
"regenerator-runtime": "0.13.11", | ||
"semantic-release": "19.0.5", | ||
"semantic-release": "21.0.0", | ||
"ts-jest": "29.0.5", | ||
"ts-node": "10.9.1", | ||
"tweetnacl": "1.0.3", | ||
"typescript": "4.9.5", | ||
"webpack": "5.76.3", | ||
"webpack-cli": "4.10.0" | ||
"typescript": "5.0.2", | ||
"webpack": "5.77.0", | ||
"webpack-cli": "5.0.1" | ||
}, | ||
"dependencies": { | ||
"@stablelib/ed25519": "^1.0.2", | ||
"@stablelib/random": "^1.0.1", | ||
"@stablelib/ed25519": "^1.0.3", | ||
"@stablelib/random": "^1.0.2", | ||
"@stablelib/sha256": "^1.0.1", | ||
"@stablelib/x25519": "^1.0.2", | ||
"@stablelib/x25519": "^1.0.3", | ||
"@stablelib/xchacha20poly1305": "^1.0.1", | ||
"bech32": "^2.0.0", | ||
"canonicalize": "^2.0.0", | ||
"did-resolver": "^4.0.0", | ||
"did-resolver": "^4.1.0", | ||
"elliptic": "^6.5.4", | ||
"js-sha3": "^0.8.0", | ||
"multiformats": "^9.6.5", | ||
"uint8arrays": "^3.0.0" | ||
"multiformats": "^11.0.2", | ||
"uint8arrays": "^4.0.3" | ||
}, | ||
@@ -113,0 +102,0 @@ "eslintIgnore": [ |
@@ -1,3 +0,3 @@ | ||
import VerifierAlgorithm from '../VerifierAlgorithm' | ||
import { verifyJWT } from '../JWT' | ||
import VerifierAlgorithm from '../VerifierAlgorithm.js' | ||
import { verifyJWT } from '../JWT.js' | ||
@@ -19,3 +19,3 @@ const edKey58 = { | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
return expect(verifier(parts[1], parts[2], [edKey58])).toEqual(edKey58) | ||
return expect(verifier(parts!![1], parts!![2], [edKey58])).toEqual(edKey58) | ||
}) | ||
@@ -22,0 +22,0 @@ |
@@ -1,4 +0,6 @@ | ||
import { keccak, ripemd160, sha256, toEthereumAddress } from '../Digest' | ||
import * as u8a from 'uint8arrays' | ||
import { keccak, ripemd160, sha256, toEthereumAddress } from '../Digest.js' | ||
import { toString, fromString } from 'uint8arrays' | ||
const u8a = { toString, fromString } | ||
// https://www.di-mgt.com.au/sha_testvectors.html | ||
@@ -5,0 +7,0 @@ describe('sha256', () => { |
@@ -1,3 +0,3 @@ | ||
import { base64ToBytes, base58ToBytes, hexToBytes } from '../util' | ||
import { EdDSASigner } from '../signers/EdDSASigner' | ||
import { base64ToBytes, base58ToBytes, hexToBytes } from '../util.js' | ||
import { EdDSASigner } from '../signers/EdDSASigner.js' | ||
@@ -4,0 +4,0 @@ describe('EdDSASigner', () => { |
@@ -1,2 +0,2 @@ | ||
import EllipticSigner from '../signers/EllipticSigner' | ||
import EllipticSigner from '../signers/EllipticSigner.js' | ||
@@ -3,0 +3,0 @@ const privateKey = '278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f' |
@@ -1,3 +0,3 @@ | ||
import { hexToBytes, base58ToBytes, base64ToBytes } from '../util' | ||
import { ES256KSigner } from '../signers/ES256KSigner' | ||
import { hexToBytes, base58ToBytes, base64ToBytes } from '../util.js' | ||
import { ES256KSigner } from '../signers/ES256KSigner.js' | ||
@@ -4,0 +4,0 @@ describe('Secp256k1 Signer', () => { |
@@ -1,3 +0,3 @@ | ||
import { hexToBytes, base58ToBytes, base64ToBytes } from '../util' | ||
import { ES256Signer } from '../signers/ES256Signer' | ||
import { hexToBytes, base58ToBytes, base64ToBytes } from '../util.js' | ||
import { ES256Signer } from '../signers/ES256Signer.js' | ||
@@ -4,0 +4,0 @@ describe('Secp256r1 Signer', () => { |
@@ -1,21 +0,23 @@ | ||
import { decryptJWE, createJWE, Encrypter, JWE } from '../JWE' | ||
import vectors from './jwe-vectors.js' | ||
import { createJWE, Decrypter, decryptJWE, Encrypter, JWE } from '../JWE.js' | ||
import { vectors } from './jwe-vectors.js' | ||
import { | ||
xc20pDirEncrypter, | ||
xc20pDirDecrypter, | ||
createAnonDecrypter, | ||
createAnonEncrypter, | ||
createAuthDecrypter, | ||
createAuthEncrypter, | ||
x25519Decrypter, | ||
x25519Encrypter, | ||
x25519Decrypter, | ||
xc20pAuthDecrypterEcdh1PuV3x25519WithXc20PkwV2, | ||
xc20pAuthEncrypterEcdh1PuV3x25519WithXc20PkwV2, | ||
createAnonEncrypter, | ||
createAnonDecrypter, | ||
createAuthEncrypter, | ||
createAuthDecrypter, | ||
} from '../xc20pEncryption' | ||
import { bytesToBase64, decodeBase64url, encodeBase64url } from '../util' | ||
import * as u8a from 'uint8arrays' | ||
xc20pDirDecrypter, | ||
xc20pDirEncrypter, | ||
} from '../xc20pEncryption.js' | ||
import { decodeBase64url, encodeBase64url } from '../util.js' | ||
import { fromString, toString } from 'uint8arrays' | ||
import { randomBytes } from '@stablelib/random' | ||
import { generateKeyPairFromSeed } from '@stablelib/x25519' | ||
import { createX25519ECDH, ECDH } from '../ECDH' | ||
import { createX25519ECDH, ECDH } from '../ECDH.js' | ||
const u8a = { toString, fromString } | ||
describe('JWE', () => { | ||
@@ -105,3 +107,3 @@ describe('decryptJWE', () => { | ||
describe('Direct encryption', () => { | ||
let key, cleartext, encrypter, decrypter | ||
let key: Uint8Array, cleartext: Uint8Array, encrypter: Encrypter, decrypter: Decrypter | ||
@@ -135,3 +137,3 @@ beforeEach(() => { | ||
const jwe = await createJWE(cleartext, [encrypter], { more: 'protected' }, aad) | ||
expect(u8a.fromString(jwe.aad, 'base64url')).toEqual(aad) | ||
expect(u8a.fromString(jwe.aad!!, 'base64url')).toEqual(aad) | ||
expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ alg: 'dir', enc: 'XC20P', more: 'protected' }) | ||
@@ -146,3 +148,3 @@ expect(await decryptJWE(jwe, decrypter)).toEqual(cleartext) | ||
describe('One recipient', () => { | ||
let pubkey, secretkey, cleartext, encrypter, decrypter | ||
let pubkey, secretkey, cleartext: Uint8Array, encrypter: Encrypter, decrypter: Decrypter | ||
@@ -177,3 +179,3 @@ beforeEach(() => { | ||
const jwe = await createJWE(cleartext, [encrypter], { more: 'protected' }, aad) | ||
expect(u8a.fromString(jwe.aad, 'base64url')).toEqual(aad) | ||
expect(u8a.fromString(jwe.aad!!, 'base64url')).toEqual(aad) | ||
expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'XC20P', more: 'protected' }) | ||
@@ -187,4 +189,4 @@ expect(await decryptJWE(jwe, decrypter)).toEqual(cleartext) | ||
describe('Multiple recipients', () => { | ||
let pubkey1, secretkey1, pubkey2, secretkey2, cleartext | ||
let encrypter1, decrypter1, encrypter2, decrypter2 | ||
let pubkey1, secretkey1, pubkey2, secretkey2, cleartext: Uint8Array | ||
let encrypter1: Encrypter, decrypter1: Decrypter, encrypter2: Encrypter, decrypter2: Decrypter | ||
@@ -225,3 +227,3 @@ beforeEach(() => { | ||
const jwe = await createJWE(cleartext, [encrypter1, encrypter2], { more: 'protected' }, aad) | ||
expect(u8a.fromString(jwe.aad, 'base64url')).toEqual(aad) | ||
expect(u8a.fromString(jwe.aad!!, 'base64url')).toEqual(aad) | ||
expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'XC20P', more: 'protected' }) | ||
@@ -247,3 +249,3 @@ expect(await decryptJWE(jwe, decrypter1)).toEqual(cleartext) | ||
describe('One recipient', () => { | ||
let cleartext, recipientKey, senderKey, decrypter | ||
let cleartext: Uint8Array, recipientKey: any, senderKey: any, decrypter: Decrypter | ||
@@ -275,5 +277,5 @@ beforeEach(() => { | ||
expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'XC20P' }) | ||
expect(jwe.recipients[0].header.kid).toEqual(kid) | ||
expect(jwe.recipients[0].header.apu).toBeUndefined() | ||
expect(jwe.recipients[0].header.apv).toBeUndefined() | ||
expect(jwe.recipients!![0].header.kid).toEqual(kid) | ||
expect(jwe.recipients!![0].header.apu).toBeUndefined() | ||
expect(jwe.recipients!![0].header.apv).toBeUndefined() | ||
expect(await decryptJWE(jwe, decrypter)).toEqual(cleartext) | ||
@@ -293,5 +295,5 @@ }) | ||
expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'XC20P' }) | ||
expect(jwe.recipients[0].header.kid).toBeUndefined() | ||
expect(jwe.recipients[0].header.apu).toEqual(apu) | ||
expect(jwe.recipients[0].header.apv).toEqual(apv) | ||
expect(jwe.recipients!![0].header.kid).toBeUndefined() | ||
expect(jwe.recipients!![0].header.apu).toEqual(apu) | ||
expect(jwe.recipients!![0].header.apv).toEqual(apv) | ||
expect(await decryptJWE(jwe, decrypter)).toEqual(cleartext) | ||
@@ -313,5 +315,5 @@ }) | ||
expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'XC20P' }) | ||
expect(jwe.recipients[0].header.kid).toEqual(kid) | ||
expect(jwe.recipients[0].header.apu).toEqual(apu) | ||
expect(jwe.recipients[0].header.apv).toEqual(apv) | ||
expect(jwe.recipients!![0].header.kid).toEqual(kid) | ||
expect(jwe.recipients!![0].header.apu).toEqual(apu) | ||
expect(jwe.recipients!![0].header.apv).toEqual(apv) | ||
expect(await decryptJWE(jwe, decrypter)).toEqual(cleartext) | ||
@@ -335,3 +337,3 @@ }) | ||
const jwe = await createJWE(cleartext, [encrypter], { more: 'protected' }, aad) | ||
expect(u8a.fromString(jwe.aad, 'base64url')).toEqual(aad) | ||
expect(u8a.fromString(jwe.aad!!, 'base64url')).toEqual(aad) | ||
expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'XC20P', more: 'protected' }) | ||
@@ -386,4 +388,4 @@ expect(await decryptJWE(jwe, decrypter)).toEqual(cleartext) | ||
describe('Multiple recipients', () => { | ||
let cleartext, senderkey | ||
const recipients = [] | ||
let cleartext: any, senderkey: any | ||
const recipients: any[] = [] | ||
@@ -458,3 +460,3 @@ beforeEach(() => { | ||
) | ||
expect(u8a.fromString(jwe.aad, 'base64url')).toEqual(aad) | ||
expect(u8a.fromString(jwe.aad!!, 'base64url')).toEqual(aad) | ||
expect(JSON.parse(decodeBase64url(jwe.protected))).toEqual({ enc: 'XC20P', more: 'protected' }) | ||
@@ -461,0 +463,0 @@ expect(await decryptJWE(jwe, recipients[0].decrypter)).toEqual(cleartext) |
@@ -1,6 +0,5 @@ | ||
import { hexToBytes, base64ToBytes } from '../util' | ||
import { VerificationMethod } from 'did-resolver' | ||
import { base64ToBytes, bytesToBase64url, decodeBase64url, hexToBytes } from '../util.js' | ||
import { Resolvable, VerificationMethod } from 'did-resolver' | ||
import { TokenVerifier } from 'jsontokens' | ||
import MockDate from 'mockdate' | ||
import { fromString } from 'uint8arrays/from-string' | ||
import { getAddress } from '@ethersproject/address' | ||
@@ -17,13 +16,17 @@ import { | ||
verifyJWT, | ||
} from '../JWT' | ||
import { EdDSASigner } from '../signers/EdDSASigner' | ||
import { ES256KSigner } from '../signers/ES256KSigner' | ||
import { bytesToBase64url, decodeBase64url } from '../util' | ||
} from '../JWT.js' | ||
import { EdDSASigner } from '../signers/EdDSASigner.js' | ||
import { ES256KSigner } from '../signers/ES256KSigner.js' | ||
// add declarations for ES256 Tests | ||
import { ES256Signer } from '../signers/ES256Signer' | ||
import { ES256Signer } from '../signers/ES256Signer.js' | ||
import * as jwt from 'jsonwebtoken' | ||
import * as u8a from 'uint8arrays' | ||
import * as jwkToPem from 'jwk-to-pem' | ||
import { fromString, toString } from 'uint8arrays' | ||
// @ts-ignore | ||
import jwkToPem from 'jwk-to-pem' | ||
import { jest } from '@jest/globals' | ||
const u8a = { fromString, toString } | ||
const NOW = 1485321133 | ||
@@ -124,3 +127,2 @@ MockDate.set(NOW * 1000 + 123) | ||
describe('ES256', () => { | ||
const alg = 'ES256' | ||
const privateKey = '736f625c9dda78a94bb16840c82779bb7bc18014b8ede52f0f03429902fc4ba8' | ||
@@ -146,7 +148,7 @@ const publicKey_x = '14c58e581c7656ba153195669fe4ce53ff78dd5ede60a4039771a90c58cb41de' | ||
function verifyTokenFormAndValidity(token: string, pemPublic: string): boolean { | ||
let result = null | ||
let result | ||
try { | ||
jwt.verify(token, pemPublic) | ||
result = true | ||
} catch (e) { | ||
} catch (e: any) { | ||
console.error(e.name + ': ' + e.message) | ||
@@ -183,20 +185,6 @@ result = false | ||
// input private key in hex, and export pem | ||
function privateToJWK(privatePointHex: string, kty_value: string, crv_value: string): privateJsonWebKey { | ||
if (privatePointHex.length % 2 != 0) { | ||
privatePointHex = '0' + privatePointHex | ||
} | ||
const privatePointUint8 = u8a.fromString(privatePointHex, 'hex') | ||
const privatePointBase64URL = u8a.toString(privatePointUint8, 'base64url') | ||
return { | ||
kty: kty_value, | ||
crv: crv_value, | ||
d: privatePointBase64URL, | ||
} | ||
} | ||
it('creates a valid JWT', async () => { | ||
expect.assertions(1) | ||
const jwt = await createJWT({ requested: ['name', 'phone'] }, { issuer: did, signer }, { alg: 'ES256' }) | ||
const pemPublic = jwkToPem.default(publicToJWK(publicKey_x, publicKey_y, 'EC', 'P-256')) | ||
const pemPublic = jwkToPem(publicToJWK(publicKey_x, publicKey_y, 'EC', 'P-256') as any) | ||
expect(verifyTokenFormAndValidity(jwt, pemPublic)).toBe(true) | ||
@@ -208,3 +196,3 @@ }) | ||
const jwt = await createJWT({ requested: ['name', 'phone'] }, { issuer: address, signer }, { alg: 'ES256' }) | ||
const pemPublic = jwkToPem.default(publicToJWK(publicKey_x, publicKey_y, 'EC', 'P-256')) | ||
const pemPublic = jwkToPem(publicToJWK(publicKey_x, publicKey_y, 'EC', 'P-256') as any) | ||
expect(verifyTokenFormAndValidity(jwt, pemPublic)).toBe(true) | ||
@@ -236,3 +224,3 @@ }) | ||
const { payload } = decodeJWT(jwt) | ||
return expect(payload.exp).toEqual(payload.nbf + 10000) | ||
return expect(payload.exp).toEqual(payload.nbf!! + 10000) | ||
}) | ||
@@ -245,3 +233,3 @@ | ||
) | ||
return expect(payload.exp).toEqual(payload.iat + 10000) | ||
return expect(payload.exp).toEqual(payload.iat!! + 10000) | ||
}) | ||
@@ -253,3 +241,10 @@ | ||
const { payload } = decodeJWT( | ||
await createJWT({ requested: ['name', 'phone'] }, { issuer: did, signer }, { alg: 'ES256' }) | ||
await createJWT( | ||
{ requested: ['name', 'phone'] }, | ||
{ | ||
issuer: did, | ||
signer, | ||
}, | ||
{ alg: 'ES256' } | ||
) | ||
) | ||
@@ -321,3 +316,3 @@ return expect(payload.iat).toEqual(timestamp) | ||
const { payload } = decodeJWT(jwt) | ||
return expect(payload.exp).toEqual(payload.nbf + 10000) | ||
return expect(payload.exp).toEqual(payload.nbf!! + 10000) | ||
}) | ||
@@ -330,3 +325,3 @@ | ||
) | ||
return expect(payload.exp).toEqual(payload.iat + 10000) | ||
return expect(payload.exp).toEqual(payload.iat!! + 10000) | ||
}) | ||
@@ -388,3 +383,3 @@ | ||
}), | ||
} | ||
} as Resolvable | ||
@@ -446,3 +441,3 @@ it('creates a valid JWT with did:nacl issuer', async () => { | ||
const { payload } = decodeJWT(jwt) | ||
return expect(payload.exp).toEqual(payload.nbf + 10000) | ||
return expect(payload.exp).toEqual(payload.nbf!! + 10000) | ||
}) | ||
@@ -453,7 +448,4 @@ }) | ||
describe('verifyJWT() for ES256', () => { | ||
const alg = 'ES256' | ||
const privateKey = '736f625c9dda78a94bb16840c82779bb7bc18014b8ede52f0f03429902fc4ba8' | ||
const publicKey = '0314c58e581c7656ba153195669fe4ce53ff78dd5ede60a4039771a90c58cb41de' | ||
const publicKey_x = '14c58e581c7656ba153195669fe4ce53ff78dd5ede60a4039771a90c58cb41de' | ||
const publicKey_y = 'ec41869995bd661849414c523c7dff9a96f1c8dbc2e5e78172118f91c7199869' | ||
// construct did:key for secp256r1 (unlike did for secp256k1 which is for an Ethereum Address) | ||
@@ -484,3 +476,3 @@ // const multicodecName = 'p256-pub'; | ||
const resolver = { | ||
resolve: jest.fn().mockImplementation((didUrl: string) => { | ||
resolve: jest.fn(async (didUrl: string) => { | ||
if (didUrl.includes(did)) { | ||
@@ -503,3 +495,3 @@ return { | ||
}), | ||
} | ||
} as Resolvable | ||
@@ -561,3 +553,3 @@ describe('pregenerated JWT', () => { | ||
expect.assertions(1) | ||
await expect(() => verifyJWT(incomingJwt, { resolver, proofPurpose: 'impossible' })).rejects.toThrowError( | ||
await expect(() => verifyJWT(incomingJwt, { resolver, proofPurpose: 'impossible' as any })).rejects.toThrowError( | ||
`DID document for ${did} does not have public keys suitable for ES256 with impossible purpose` | ||
@@ -571,3 +563,3 @@ ) | ||
const resolver = { | ||
resolve: jest.fn().mockImplementation((didUrl: string) => { | ||
resolve: jest.fn(async (didUrl: string) => { | ||
if (didUrl.includes(did)) { | ||
@@ -598,3 +590,3 @@ return { | ||
}), | ||
} | ||
} as Resolvable | ||
@@ -656,3 +648,3 @@ describe('pregenerated JWT', () => { | ||
expect.assertions(1) | ||
await expect(() => verifyJWT(incomingJwt, { resolver, proofPurpose: 'impossible' })).rejects.toThrowError( | ||
await expect(() => verifyJWT(incomingJwt, { resolver, proofPurpose: 'impossible' as any })).rejects.toThrowError( | ||
`DID document for ${did} does not have public keys suitable for ES256K with impossible purpose` | ||
@@ -666,3 +658,3 @@ ) | ||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE0ODUzMjExMzMsImlzcyI6ImRpZDpldGhyOjB4OTBlNDVkNzViZDEyNDZlMDkyNDg3MjAxODY0N2RiYTk5NmE4ZTdiOSIsInJlcXVlc3RlZCI6WyJuYW1lIiwicGhvbmUiXX0.KIG2zUO8Quf3ucb9jIncZ1CmH0v-fAZlsKvesfsd9x4RzU0qrvinVd9d30DOeZOwdwEdXkET_wuPoOECwU0IKA' | ||
const jwkResolver = { resolve: jest.fn().mockReturnValue(didDocJwk) } | ||
const jwkResolver = { resolve: jest.fn().mockReturnValue(didDocJwk) } as Resolvable | ||
@@ -693,3 +685,3 @@ it('verifies the JWT and return correct payload', async () => { | ||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE0ODUzMjExMzMsImlzcyI6ImRpZDpldGhyOjB4OTBlNDVkNzViZDEyNDZlMDkyNDg3MjAxODY0N2RiYTk5NmE4ZTdiOSIsInJlcXVlc3RlZCI6WyJuYW1lIiwicGhvbmUiXX0.KIG2zUO8Quf3ucb9jIncZ1CmH0v-fAZlsKvesfsd9x4RzU0qrvinVd9d30DOeZOwdwEdXkET_wuPoOECwU0IKA' | ||
const legacyResolver = { resolve: jest.fn().mockReturnValue(didDocLegacy) } | ||
const legacyResolver = { resolve: jest.fn().mockReturnValue(didDocLegacy) } as Resolvable | ||
@@ -872,3 +864,3 @@ it('verifies the JWT and return correct payload', async () => { | ||
}), | ||
} | ||
} as Resolvable | ||
const jwt = await createJWT({ hello: 'world' }, { issuer: aud, signer, alg: 'ES256K' }) | ||
@@ -895,3 +887,3 @@ const { payload } = await verifyJWT(jwt, { resolver: ethResolver }) | ||
}), | ||
} | ||
} as Resolvable | ||
const jwt = await createJWT({ hello: 'world' }, { issuer: aud, signer, alg: 'ES256K' }) | ||
@@ -917,3 +909,3 @@ const { payload } = await verifyJWT(jwt, { resolver: ethResolver }) | ||
}), | ||
} | ||
} as Resolvable | ||
const jwt = await createJWT({ hello: 'world' }, { issuer: aud, signer: recoverySigner, alg: 'ES256K-R' }) | ||
@@ -1270,3 +1262,7 @@ const result = await verifyJWT(jwt, { resolver: ethResolver }) | ||
expect.assertions(1) | ||
const authenticators = await resolveAuthenticator({ resolve: jest.fn().mockReturnValue(singleKey) }, alg, did) | ||
const authenticators = await resolveAuthenticator( | ||
{ resolve: jest.fn().mockReturnValue(singleKey) } as Resolvable, | ||
alg, | ||
did | ||
) | ||
return expect(authenticators).toEqual({ | ||
@@ -1282,3 +1278,3 @@ authenticators: [ecKey1], | ||
const authenticators = await resolveAuthenticator( | ||
{ resolve: jest.fn().mockReturnValue(multipleKeysLegacy) }, | ||
{ resolve: jest.fn().mockReturnValue(multipleKeysLegacy) } as Resolvable, | ||
alg, | ||
@@ -1297,3 +1293,3 @@ did | ||
const authenticators = await resolveAuthenticator( | ||
{ resolve: jest.fn().mockReturnValue(multipleKeysLegacy) }, | ||
{ resolve: jest.fn().mockReturnValue(multipleKeysLegacy) } as Resolvable, | ||
alg, | ||
@@ -1313,3 +1309,3 @@ did, | ||
const authenticators = await resolveAuthenticator( | ||
{ resolve: jest.fn().mockReturnValue(multipleAuthTypes) }, | ||
{ resolve: jest.fn().mockReturnValue(multipleAuthTypes) } as Resolvable, | ||
alg, | ||
@@ -1329,3 +1325,3 @@ did, | ||
return await expect( | ||
resolveAuthenticator({ resolve: jest.fn().mockReturnValue(unsupportedFormat) }, alg, did) | ||
resolveAuthenticator({ resolve: jest.fn().mockReturnValue(unsupportedFormat) } as Resolvable, alg, did) | ||
).rejects.toThrowError(`DID document for ${did} does not have public keys for ${alg}`) | ||
@@ -1340,3 +1336,3 @@ }) | ||
const authenticators = await resolveAuthenticator( | ||
{ resolve: jest.fn().mockReturnValue(multipleKeysLegacy) }, | ||
{ resolve: jest.fn().mockReturnValue(multipleKeysLegacy) } as Resolvable, | ||
alg, | ||
@@ -1355,3 +1351,3 @@ did | ||
const authenticators = await resolveAuthenticator( | ||
{ resolve: jest.fn().mockReturnValue(multipleKeysLegacy) }, | ||
{ resolve: jest.fn().mockReturnValue(multipleKeysLegacy) } as Resolvable, | ||
alg, | ||
@@ -1371,3 +1367,3 @@ did, | ||
const authenticators = await resolveAuthenticator( | ||
{ resolve: jest.fn().mockReturnValue(multipleAuthTypes) }, | ||
{ resolve: jest.fn().mockReturnValue(multipleAuthTypes) } as Resolvable, | ||
alg, | ||
@@ -1387,3 +1383,3 @@ did, | ||
return await expect( | ||
resolveAuthenticator({ resolve: jest.fn().mockReturnValue(unsupportedFormat) }, alg, did) | ||
resolveAuthenticator({ resolve: jest.fn().mockReturnValue(unsupportedFormat) } as Resolvable, alg, did) | ||
).rejects.toThrowError(`DID document for ${did} does not have public keys for ${alg}`) | ||
@@ -1396,3 +1392,8 @@ }) | ||
return await expect( | ||
resolveAuthenticator({ resolve: jest.fn().mockReturnValue(singleKey) }, alg, did, 'authentication') | ||
resolveAuthenticator( | ||
{ resolve: jest.fn().mockReturnValue(singleKey) } as Resolvable, | ||
alg, | ||
did, | ||
'authentication' | ||
) | ||
).rejects.toThrowError( | ||
@@ -1406,3 +1407,3 @@ `DID document for ${did} does not have public keys suitable for ES256K with authentication purpose` | ||
return await expect( | ||
resolveAuthenticator({ resolve: jest.fn().mockReturnValue(noPublicKey) }, alg, did) | ||
resolveAuthenticator({ resolve: jest.fn().mockReturnValue(noPublicKey) } as Resolvable, alg, did) | ||
).rejects.toThrowError(`DID document for ${did} does not have public keys for ${alg}`) | ||
@@ -1420,3 +1421,3 @@ }) | ||
}), | ||
}, | ||
} as Resolvable, | ||
alg, | ||
@@ -1431,3 +1432,3 @@ did | ||
return await expect( | ||
resolveAuthenticator({ resolve: jest.fn().mockReturnValue(singleKey) }, 'ESBAD', did) | ||
resolveAuthenticator({ resolve: jest.fn().mockReturnValue(singleKey) } as Resolvable, 'ESBAD', did) | ||
).rejects.toThrowError('No supported signature types for algorithm ESBAD') | ||
@@ -1434,0 +1435,0 @@ }) |
@@ -1,2 +0,2 @@ | ||
import NaclSigner from '../signers/NaclSigner' | ||
import NaclSigner from '../signers/NaclSigner.js' | ||
@@ -3,0 +3,0 @@ const privateKey = 'nlXR4aofRVuLqtn9+XVQNlX4s1nVQvp+TOhBBtYls1IG+sHyIkDP/WN+rWZHGIQp+v2pyct+rkM4asF/YRFQdQ==' |
@@ -1,11 +0,16 @@ | ||
import SignerAlgorithm from '../SignerAlgorithm' | ||
import { toSignatureObject } from '../VerifierAlgorithm' | ||
import SimpleSigner from '../signers/SimpleSigner' | ||
import EllipticSigner from '../signers/EllipticSigner' | ||
import NaclSigner from '../signers/NaclSigner' | ||
import { ec as EC } from 'elliptic' | ||
// @ts-ignore | ||
import elliptic from 'elliptic' | ||
// @ts-ignore | ||
import nacl from 'tweetnacl' | ||
import { base64ToBytes, stringToBytes } from '../util' | ||
import { sha256 } from '../Digest' | ||
const secp256k1 = new EC('secp256k1') | ||
import SignerAlgorithm from '../SignerAlgorithm.js' | ||
import { toSignatureObject } from '../VerifierAlgorithm.js' | ||
import SimpleSigner from '../signers/SimpleSigner.js' | ||
import EllipticSigner from '../signers/EllipticSigner.js' | ||
import NaclSigner from '../signers/NaclSigner.js' | ||
import { base64ToBytes, hexToBytes, stringToBytes } from '../util.js' | ||
import { sha256 } from '../Digest.js' | ||
import { ES256Signer } from '../signers/ES256Signer.js' | ||
const secp256k1 = new elliptic.ec('secp256k1') | ||
const privateKey = '0278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a241154cc1d25383f' | ||
@@ -20,5 +25,4 @@ const ed25519PrivateKey = 'nlXR4aofRVuLqtn9+XVQNlX4s1nVQvp+TOhBBtYls1IG+sHyIkDP/WN+rWZHGIQp+v2pyct+rkM4asF/YRFQdQ==' | ||
// Add tests specific to new ES256 signer for curve secp256r1 / P-256 | ||
const secp256r1 = new EC('p256') | ||
import { ES256Signer } from '../signers/ES256Signer' | ||
import { hexToBytes } from '../util' | ||
const secp256r1 = new elliptic.ec('p256') | ||
const p256privateKey = '736f625c9dda78a94bb16840c82779bb7bc18014b8ede52f0f03429902fc4ba8' | ||
@@ -25,0 +29,0 @@ const p256kp = secp256r1.keyFromPrivate(p256privateKey) |
@@ -1,2 +0,2 @@ | ||
import SimpleSigner from '../signers/SimpleSigner' | ||
import SimpleSigner from '../signers/SimpleSigner.js' | ||
@@ -3,0 +3,0 @@ const privateKey = '278a5de700e29faae8e40e366ec5012b5ec63d36ec77e8a2417154cc1d25383f' |
@@ -1,15 +0,19 @@ | ||
import VerifierAlgorithm from '../VerifierAlgorithm' | ||
import { createJWT } from '../JWT' | ||
// @ts-ignore | ||
import nacl from 'tweetnacl' | ||
import { ec as EC } from 'elliptic' | ||
import { base64ToBytes, bytesToBase58, bytesToBase64, hexToBytes, bytesToBase64url, bytesToMultibase } from '../util' | ||
import * as u8a from 'uint8arrays' | ||
import { EdDSASigner } from '../signers/EdDSASigner' | ||
import { ES256KSigner } from '../signers/ES256KSigner' | ||
import { toEthereumAddress } from '../Digest' | ||
import { publicKeyToAddress as toBip122Address } from '../blockchains/bip122' | ||
import { publicKeyToAddress as toCosmosAddressWithoutPrefix } from '../blockchains/cosmos' | ||
// @ts-ignore | ||
import elliptic from 'elliptic' | ||
import { fromString, toString } from 'uint8arrays' | ||
import VerifierAlgorithm from '../VerifierAlgorithm.js' | ||
import { createJWT } from '../JWT.js' | ||
import { base64ToBytes, bytesToBase58, bytesToBase64, bytesToBase64url, bytesToMultibase, hexToBytes } from '../util.js' | ||
import { EdDSASigner } from '../signers/EdDSASigner.js' | ||
import { ES256KSigner } from '../signers/ES256KSigner.js' | ||
import { toEthereumAddress } from '../Digest.js' | ||
import { publicKeyToAddress as toBip122Address } from '../blockchains/bip122.js' | ||
import { publicKeyToAddress as toCosmosAddressWithoutPrefix } from '../blockchains/cosmos.js' | ||
import { ES256Signer } from '../signers/ES256Signer' | ||
import { ES256Signer } from '../signers/ES256Signer.js' | ||
const u8a = { toString, fromString } | ||
describe('VerifierAlgorithm', () => { | ||
@@ -38,3 +42,3 @@ it('supports ES256', () => { | ||
describe('ES256', () => { | ||
const secp256r1 = new EC('p256') | ||
const secp256r1 = new elliptic.ec('p256') | ||
const mnid = '2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX' | ||
@@ -107,2 +111,3 @@ const did = `did:uport:${mnid}` | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, ecKey2])).toEqual(ecKey2) | ||
@@ -116,3 +121,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyBase58 }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -126,3 +133,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyBase64 }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -136,3 +145,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyJwk }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -146,3 +157,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyMultibase }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -155,2 +168,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, compressedKey])).toEqual(compressedKey) | ||
@@ -163,2 +177,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(() => verifier(parts[1], parts[2], [ecKey1])).toThrowError( | ||
@@ -173,2 +188,3 @@ new Error('invalid_signature: Signature invalid for JWT') | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(() => verifier(parts[1], parts[2], [ecKey1])).toThrowError(new Error('wrong signature length')) | ||
@@ -180,2 +196,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [malformedKey1, malformedKey2, malformedKey3, compressedKey])).toEqual( | ||
@@ -187,3 +204,3 @@ compressedKey | ||
const secp256k1 = new EC('secp256k1') | ||
const secp256k1 = new elliptic.ec('secp256k1') | ||
const mnid = '2nQtiQG6Cgm1GYTBaaKAgr76uY7iSexUkqX' | ||
@@ -205,3 +222,3 @@ const did = `did:uport:${mnid}` | ||
const eip155 = toEthereumAddress(publicKey) | ||
const bip122 = toBip122Address(publicKey) | ||
const bip122 = toBip122Address(publicKey, 'undefined') | ||
const cosmosPrefix = 'example' | ||
@@ -326,2 +343,3 @@ const cosmos = toCosmosAddressWithoutPrefix(publicKey, cosmosPrefix) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, ecKey2])).toEqual(ecKey2) | ||
@@ -335,3 +353,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyBase58 }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -345,3 +365,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyBase64 }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -355,3 +377,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyJwk }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -365,3 +389,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyMultibase }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -374,2 +400,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, compressedKey])).toEqual(compressedKey) | ||
@@ -382,2 +409,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(() => verifier(parts[1], parts[2], [ecKey1])).toThrowError( | ||
@@ -392,2 +420,3 @@ new Error('invalid_signature: Signature invalid for JWT') | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(() => verifier(parts[1], parts[2], [ecKey1])).toThrowError(new Error('wrong signature length')) | ||
@@ -399,2 +428,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [malformedKey1, malformedKey2, malformedKey3, compressedKey])).toEqual( | ||
@@ -409,2 +439,3 @@ compressedKey | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ethAddress])).toEqual(ethAddress) | ||
@@ -417,2 +448,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [blockchainAddress])).toEqual(blockchainAddress) | ||
@@ -425,2 +457,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [blockchainAddressCaip10])).toEqual(blockchainAddressCaip10) | ||
@@ -433,2 +466,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [blockchainAddressBip122])).toEqual(blockchainAddressBip122) | ||
@@ -441,2 +475,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [blockchainAddressCosmos])).toEqual(blockchainAddressCosmos) | ||
@@ -449,2 +484,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [recoveryMethod2020Key])).toEqual(recoveryMethod2020Key) | ||
@@ -461,2 +497,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, ecKey2])).toEqual(ecKey2) | ||
@@ -469,2 +506,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, compressedKey])).toEqual(compressedKey) | ||
@@ -477,2 +515,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, ethAddress])).toEqual(ethAddress) | ||
@@ -485,2 +524,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, blockchainAddress])).toEqual(blockchainAddress) | ||
@@ -493,2 +533,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, blockchainAddressCaip10])).toEqual(blockchainAddressCaip10) | ||
@@ -501,2 +542,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, blockchainAddressBip122])).toEqual(blockchainAddressBip122) | ||
@@ -509,2 +551,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, blockchainAddressCosmos])).toEqual(blockchainAddressCosmos) | ||
@@ -517,2 +560,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [ecKey1, recoveryMethod2020Key])).toEqual(recoveryMethod2020Key) | ||
@@ -526,3 +570,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyBase58 }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -536,3 +582,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyBase64 }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -546,3 +594,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyJwk }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -556,3 +606,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyMultibase }, ecKey2) | ||
// @ts-ignore | ||
delete pubkey.publicKeyHex | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -565,2 +617,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(() => verifier(parts[1], parts[2], [ecKey1])).toThrowError( | ||
@@ -578,2 +631,3 @@ new Error('invalid_signature: Signature invalid for JWT') | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [edKey, edKey2])).toEqual(edKey) | ||
@@ -588,3 +642,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyBase58 }, edKey) | ||
// @ts-ignore | ||
delete pubkey.publicKeyBase64 | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -603,3 +659,5 @@ }) | ||
const pubkey = Object.assign({ publicKeyJwk }, edKey) | ||
// @ts-ignore | ||
delete pubkey.publicKeyBase64 | ||
// @ts-ignore | ||
return expect(verifier(parts[1], parts[2], [pubkey])).toEqual(pubkey) | ||
@@ -612,2 +670,3 @@ }) | ||
const parts = jwt.match(/^([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/) | ||
// @ts-ignore | ||
return expect(() => verifier(parts[1], parts[2], [edKey2])).toThrowError( | ||
@@ -614,0 +673,0 @@ new Error('invalid_signature: Signature invalid for JWT') |
@@ -1,8 +0,11 @@ | ||
import { x25519Decrypter, resolveX25519Encrypters } from '../xc20pEncryption' | ||
import { decryptJWE, createJWE } from '../JWE' | ||
import * as u8a from 'uint8arrays' | ||
import { randomBytes } from '@stablelib/random' | ||
import { generateKeyPair } from '@stablelib/x25519' | ||
import { createX25519ECDH } from '../ECDH' | ||
import { DIDResolutionResult, Resolvable } from 'did-resolver' | ||
import { resolveX25519Encrypters, x25519Decrypter } from '../xc20pEncryption.js' | ||
import { createJWE, Decrypter, decryptJWE } from '../JWE.js' | ||
import { createX25519ECDH } from '../ECDH.js' | ||
import { bytesToBase58 } from '../util.js' | ||
import { jest } from '@jest/globals' | ||
describe('xc20pEncryption', () => { | ||
@@ -20,15 +23,15 @@ describe('resolveX25519Encrypters', () => { | ||
let resolver | ||
let decrypter1, decrypter2 | ||
let decrypter1remote, decrypter2remote | ||
let resolver: Resolvable | ||
let decrypter1: Decrypter, decrypter2: Decrypter | ||
let decrypter1remote: Decrypter, decrypter2remote: Decrypter | ||
let didDocumentResult1, | ||
didDocumentResult2, | ||
didDocumentResult3, | ||
didDocumentResult4, | ||
didDocumentResult5, | ||
didDocumentResult6, | ||
didDocumentResult7, | ||
didDocumentResult8, | ||
didDocumentResult9 | ||
let didDocumentResult1: DIDResolutionResult, | ||
didDocumentResult2: DIDResolutionResult, | ||
didDocumentResult3: DIDResolutionResult, | ||
didDocumentResult4: DIDResolutionResult, | ||
didDocumentResult5: DIDResolutionResult, | ||
didDocumentResult6: DIDResolutionResult, | ||
didDocumentResult7: DIDResolutionResult, | ||
didDocumentResult8: DIDResolutionResult, | ||
didDocumentResult9: DIDResolutionResult | ||
@@ -51,3 +54,3 @@ beforeEach(() => { | ||
controller: did1, | ||
publicKeyBase58: u8a.toString(kp1.publicKey, 'base58btc'), | ||
publicKeyBase58: bytesToBase58(kp1.publicKey), | ||
}, | ||
@@ -62,3 +65,3 @@ ], | ||
}, | ||
} | ||
} as DIDResolutionResult | ||
@@ -73,10 +76,15 @@ didDocumentResult2 = { | ||
controller: did2, | ||
publicKeyBase58: u8a.toString(kp2.publicKey, 'base58btc'), | ||
publicKeyBase58: bytesToBase58(kp2.publicKey), | ||
}, | ||
], | ||
}, | ||
} | ||
} as unknown as DIDResolutionResult | ||
didDocumentResult3 = { didResolutionMetadata: { error: 'notFound' }, didDocument: null } | ||
didDocumentResult4 = { didDocument: { publicKey: [], keyAgreement: [{ type: 'wrong type' }] } } | ||
didDocumentResult3 = { didResolutionMetadata: { error: 'notFound' }, didDocument: null } as DIDResolutionResult | ||
didDocumentResult4 = { | ||
didDocument: { | ||
publicKey: [], | ||
keyAgreement: [{ type: 'wrong type' }], | ||
}, | ||
} as unknown as DIDResolutionResult | ||
@@ -95,3 +103,3 @@ didDocumentResult5 = { | ||
}, | ||
} | ||
} as DIDResolutionResult | ||
@@ -110,3 +118,3 @@ didDocumentResult6 = { | ||
}, | ||
} | ||
} as DIDResolutionResult | ||
@@ -125,3 +133,3 @@ didDocumentResult7 = { | ||
}, | ||
} | ||
} as DIDResolutionResult | ||
@@ -140,3 +148,3 @@ didDocumentResult8 = { | ||
}, | ||
} | ||
} as DIDResolutionResult | ||
@@ -155,6 +163,6 @@ didDocumentResult9 = { | ||
}, | ||
} | ||
} as DIDResolutionResult | ||
resolver = { | ||
resolve: jest.fn((did) => { | ||
resolve: jest.fn(async (did) => { | ||
switch (did) { | ||
@@ -181,3 +189,3 @@ case did1: | ||
}), | ||
} | ||
} as Resolvable | ||
}) | ||
@@ -190,4 +198,4 @@ | ||
const jwe = await createJWE(cleartext, encrypters) | ||
expect(jwe.recipients[0].header.kid).toEqual(did1 + '#abc') | ||
expect(jwe.recipients[1].header.kid).toEqual(did2 + '#abc') | ||
expect(jwe.recipients!![0].header.kid).toEqual(did1 + '#abc') | ||
expect(jwe.recipients!![1].header.kid).toEqual(did2 + '#abc') | ||
expect(await decryptJWE(jwe, decrypter1)).toEqual(cleartext) | ||
@@ -223,15 +231,15 @@ expect(await decryptJWE(jwe, decrypter2)).toEqual(cleartext) | ||
didDocumentResult1.didDocument.verificationMethod.push({ | ||
didDocumentResult1.didDocument?.verificationMethod?.push({ | ||
id: did1 + '#def', | ||
type: 'X25519KeyAgreementKey2019', | ||
controller: did1, | ||
publicKeyBase58: u8a.toString(secondKp1.publicKey, 'base58btc'), | ||
publicKeyBase58: bytesToBase58(secondKp1.publicKey), | ||
}) | ||
didDocumentResult1.didDocument.keyAgreement.push(did1 + '#def') | ||
didDocumentResult1.didDocument?.keyAgreement?.push(did1 + '#def') | ||
didDocumentResult2.didDocument.keyAgreement.push({ | ||
didDocumentResult2.didDocument?.keyAgreement?.push({ | ||
id: did2 + '#def', | ||
type: 'X25519KeyAgreementKey2019', | ||
controller: did2, | ||
publicKeyBase58: u8a.toString(secondKp2.publicKey, 'base58btc'), | ||
publicKeyBase58: bytesToBase58(secondKp2.publicKey), | ||
}) | ||
@@ -243,6 +251,6 @@ | ||
expect(jwe.recipients[0].header.kid).toEqual(did1 + '#abc') | ||
expect(jwe.recipients[1].header.kid).toEqual(did1 + '#def') | ||
expect(jwe.recipients[2].header.kid).toEqual(did2 + '#abc') | ||
expect(jwe.recipients[3].header.kid).toEqual(did2 + '#def') | ||
expect(jwe.recipients!![0].header.kid).toEqual(did1 + '#abc') | ||
expect(jwe.recipients!![1].header.kid).toEqual(did1 + '#def') | ||
expect(jwe.recipients!![2].header.kid).toEqual(did2 + '#abc') | ||
expect(jwe.recipients!![3].header.kid).toEqual(did2 + '#def') | ||
expect(await decryptJWE(jwe, newDecrypter1)).toEqual(cleartext) | ||
@@ -259,3 +267,3 @@ expect(await decryptJWE(jwe, newDecrypter2)).toEqual(cleartext) | ||
const jwe = await createJWE(cleartext, encrypters) | ||
expect(jwe.recipients[0].header.kid).toEqual(did1 + '#abc') | ||
expect(jwe.recipients!![0].header.kid).toEqual(did1 + '#abc') | ||
expect(await decryptJWE(jwe, decrypter1)).toEqual(cleartext) | ||
@@ -270,3 +278,3 @@ expect(await decryptJWE(jwe, decrypter1remote)).toEqual(cleartext) | ||
const jwe = await createJWE(cleartext, encrypters) | ||
expect(jwe.recipients[0].header.kid).toEqual(did1 + '#abc') | ||
expect(jwe.recipients!![0].header.kid).toEqual(did1 + '#abc') | ||
expect(await decryptJWE(jwe, decrypter1)).toEqual(cleartext) | ||
@@ -281,4 +289,4 @@ expect(await decryptJWE(jwe, decrypter1remote)).toEqual(cleartext) | ||
const jwe = await createJWE(cleartext, encrypters) | ||
expect(jwe.recipients[0].header.kid).toEqual(did2 + '#abc') | ||
expect(jwe.recipients.length).toEqual(1) | ||
expect(jwe.recipients!![0].header.kid).toEqual(did2 + '#abc') | ||
expect(jwe.recipients!!.length).toEqual(1) | ||
expect(await decryptJWE(jwe, decrypter2)).toEqual(cleartext) | ||
@@ -285,0 +293,0 @@ expect(await decryptJWE(jwe, decrypter2remote)).toEqual(cleartext) |
@@ -1,16 +0,15 @@ | ||
import * as u8a from 'uint8arrays' | ||
import { bytesToBase58, base58ToBytes } from '../util' | ||
import { sha256, ripemd160 } from '../Digest' | ||
import { base58ToBytes, bytesToBase58, bytesToHex, hexToBytes } from '../util.js' | ||
import { ripemd160, sha256 } from '../Digest.js' | ||
export const publicKeyToAddress = (publicKey: string, otherAddress: string): string => { | ||
// Use the same version/prefix byte as the given address. | ||
const version = u8a.toString(base58ToBytes(otherAddress).slice(0, 1), 'hex') | ||
const publicKeyBuffer = u8a.fromString(publicKey, 'hex') | ||
const version = bytesToHex(base58ToBytes(otherAddress).slice(0, 1)) | ||
const publicKeyBuffer = hexToBytes(publicKey) | ||
const publicKeyHash = ripemd160(sha256(publicKeyBuffer)) | ||
const step1 = version + u8a.toString(publicKeyHash, 'hex') | ||
const step2 = sha256(u8a.fromString(step1, 'hex')) | ||
const step1 = version + bytesToHex(publicKeyHash) | ||
const step2 = sha256(hexToBytes(step1)) | ||
const step3 = sha256(step2) | ||
const checksum = u8a.toString(step3, 'hex').substring(0, 8) | ||
const checksum = bytesToHex(step3).substring(0, 8) | ||
const step4 = step1 + checksum | ||
return bytesToBase58(u8a.fromString(step4, 'hex')) | ||
return bytesToBase58(hexToBytes(step4)) | ||
} |
import elliptic from 'elliptic' | ||
import { bech32 } from 'bech32' | ||
import * as u8a from 'uint8arrays' | ||
import { sha256, ripemd160 } from '../Digest' | ||
import { sha256, ripemd160 } from '../Digest.js' | ||
import { hexToBytes } from '../util.js' | ||
@@ -11,3 +11,3 @@ const EC = elliptic.ec | ||
const compressedPublicKey = ec.keyFromPublic(publicKey, 'hex').getPublic().encode('hex', true) | ||
const publicKeyBuffer = u8a.fromString(compressedPublicKey, 'hex') | ||
const publicKeyBuffer = hexToBytes(compressedPublicKey) | ||
const hash = ripemd160(sha256(publicKeyBuffer)) | ||
@@ -14,0 +14,0 @@ const words = bech32.toWords(hash) |
@@ -1,4 +0,4 @@ | ||
import { publicKeyToAddress as bip122 } from './bip122' | ||
import { publicKeyToAddress as cosmos } from './cosmos' | ||
import { toEthereumAddress } from '../Digest' | ||
import { publicKeyToAddress as bip122 } from './bip122.js' | ||
import { publicKeyToAddress as cosmos } from './cosmos.js' | ||
import { toEthereumAddress } from '../Digest.js' | ||
@@ -5,0 +5,0 @@ export const verifyBlockchainAccountId = (publicKey: string, blockchainAccountId: string | undefined): boolean => { |
import { hash } from '@stablelib/sha256' | ||
import { Ripemd160 } from './blockchains/utils/ripemd160' | ||
import * as u8a from 'uint8arrays' | ||
import { concat, fromString } from 'uint8arrays' | ||
import sha3 from 'js-sha3' | ||
import { bytesToHex, hexToBytes } from './util.js' | ||
import { Ripemd160 } from './blockchains/utils/ripemd160.js' | ||
export function sha256(payload: string | Uint8Array): Uint8Array { | ||
const data = typeof payload === 'string' ? u8a.fromString(payload) : payload | ||
const data = typeof payload === 'string' ? fromString(payload, 'utf-8') : payload | ||
return hash(data) | ||
@@ -16,4 +17,4 @@ } | ||
export function toEthereumAddress(hexPublicKey: string): string { | ||
const hashInput = u8a.fromString(hexPublicKey.slice(2), 'base16') | ||
return `0x${u8a.toString(keccak(hashInput).slice(-20), 'base16')}` | ||
const hashInput = hexToBytes(hexPublicKey.slice(2)) | ||
return `0x${bytesToHex(keccak(hashInput).slice(-20))}` | ||
} | ||
@@ -26,3 +27,3 @@ | ||
function writeUint32BE(value: number, array = new Uint8Array(4)): Uint8Array { | ||
const encoded = u8a.fromString(value.toString(), 'base10') | ||
const encoded = fromString(value.toString(), 'base10') | ||
array.set(encoded, 4 - encoded.length) | ||
@@ -32,3 +33,3 @@ return array | ||
const lengthAndInput = (input: Uint8Array): Uint8Array => u8a.concat([writeUint32BE(input.length), input]) | ||
const lengthAndInput = (input: Uint8Array): Uint8Array => concat([writeUint32BE(input.length), input]) | ||
@@ -46,4 +47,4 @@ // This implementation of concatKDF was inspired by these two implementations: | ||
if (keyLen !== 256) throw new Error(`Unsupported key length: ${keyLen}`) | ||
const value = u8a.concat([ | ||
lengthAndInput(u8a.fromString(alg)), | ||
const value = concat([ | ||
lengthAndInput(fromString(alg, 'utf-8')), | ||
lengthAndInput(typeof producerInfo === 'undefined' ? new Uint8Array(0) : producerInfo), // apu | ||
@@ -56,3 +57,3 @@ lengthAndInput(typeof consumerInfo === 'undefined' ? new Uint8Array(0) : consumerInfo), // apv | ||
const roundNumber = 1 | ||
return sha256(u8a.concat([writeUint32BE(roundNumber), secret, value])) | ||
return sha256(concat([writeUint32BE(roundNumber), secret, value])) | ||
} |
@@ -1,7 +0,7 @@ | ||
import SimpleSigner from './signers/SimpleSigner' | ||
import EllipticSigner from './signers/EllipticSigner' | ||
import NaclSigner from './signers/NaclSigner' | ||
import { ES256KSigner } from './signers/ES256KSigner' | ||
import { ES256Signer } from './signers/ES256Signer' | ||
import { EdDSASigner } from './signers/EdDSASigner' | ||
import SimpleSigner from './signers/SimpleSigner.js' | ||
import EllipticSigner from './signers/EllipticSigner.js' | ||
import NaclSigner from './signers/NaclSigner.js' | ||
import { ES256KSigner } from './signers/ES256KSigner.js' | ||
import { ES256Signer } from './signers/ES256Signer.js' | ||
import { EdDSASigner } from './signers/EdDSASigner.js' | ||
import { | ||
@@ -11,14 +11,23 @@ createJWS, | ||
decodeJWT, | ||
JWTHeader, | ||
JWTPayload, | ||
JWTVerified, | ||
Signer, | ||
type JWTHeader, | ||
type JWTPayload, | ||
type JWTVerified, | ||
type Signer, | ||
verifyJWS, | ||
verifyJWT, | ||
} from './JWT' | ||
import { toEthereumAddress } from './Digest' | ||
} from './JWT.js' | ||
import { toEthereumAddress } from './Digest.js' | ||
export { JWE, createJWE, decryptJWE, Encrypter, Decrypter, ProtectedHeader, Recipient, RecipientHeader } from './JWE' | ||
export { ECDH, createX25519ECDH } from './ECDH' | ||
export { | ||
type JWE, | ||
createJWE, | ||
decryptJWE, | ||
type Encrypter, | ||
type Decrypter, | ||
type ProtectedHeader, | ||
type Recipient, | ||
type RecipientHeader, | ||
} from './JWE.js' | ||
export { type ECDH, createX25519ECDH } from './ECDH.js' | ||
export { | ||
xc20pDirEncrypter, | ||
@@ -35,3 +44,3 @@ xc20pDirDecrypter, | ||
xc20pAuthDecrypterEcdh1PuV3x25519WithXc20PkwV2, | ||
} from './xc20pEncryption' | ||
} from './xc20pEncryption.js' | ||
@@ -51,12 +60,12 @@ export { | ||
toEthereumAddress, | ||
Signer, | ||
JWTHeader, | ||
JWTPayload, | ||
JWTVerified, | ||
type Signer, | ||
type JWTHeader, | ||
type JWTPayload, | ||
type JWTVerified, | ||
} | ||
export { JWTOptions, JWTVerifyOptions } from './JWT' | ||
export { type JWTOptions, type JWTVerifyOptions } from './JWT.js' | ||
export { base64ToBytes, base58ToBytes, hexToBytes } from './util' | ||
export { base64ToBytes, base58ToBytes, hexToBytes } from './util.js' | ||
export * from './Errors' | ||
export * from './Errors.js' |
import { fromString } from 'uint8arrays' | ||
import { base64ToBytes, bytesToBase64url, decodeBase64url, toSealed } from './util' | ||
import { base64ToBytes, bytesToBase64url, decodeBase64url, toSealed } from './util.js' | ||
@@ -132,3 +132,3 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const sealed = toSealed(jwe.ciphertext, jwe.tag) | ||
const aad = fromString(jwe.aad ? `${jwe.protected}.${jwe.aad}` : jwe.protected) | ||
const aad = fromString(jwe.aad ? `${jwe.protected}.${jwe.aad}` : jwe.protected, 'utf-8') | ||
let cleartext = null | ||
@@ -135,0 +135,0 @@ if (protHeader.alg === 'dir' && decrypter.alg === 'dir') { |
import canonicalizeData from 'canonicalize' | ||
import type { DIDDocument, DIDResolutionResult, Resolvable, VerificationMethod } from 'did-resolver' | ||
import SignerAlg from './SignerAlgorithm' | ||
import { decodeBase64url, EcdsaSignature, encodeBase64url } from './util' | ||
import VerifierAlgorithm from './VerifierAlgorithm' | ||
import { JWT_ERROR } from './Errors' | ||
import SignerAlg from './SignerAlgorithm.js' | ||
import { decodeBase64url, EcdsaSignature, encodeBase64url } from './util.js' | ||
import VerifierAlgorithm from './VerifierAlgorithm.js' | ||
import { JWT_ERROR } from './Errors.js' | ||
@@ -8,0 +8,0 @@ export type Signer = (data: string | Uint8Array) => Promise<EcdsaSignature | string> |
@@ -1,3 +0,3 @@ | ||
import { Signer, SignerAlgorithm } from './JWT' | ||
import { EcdsaSignature, fromJose, toJose } from './util' | ||
import type { Signer, SignerAlgorithm } from './JWT.js' | ||
import { EcdsaSignature, fromJose, toJose } from './util.js' | ||
@@ -4,0 +4,0 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any |
@@ -0,4 +1,4 @@ | ||
import type { Signer } from '../JWT.js' | ||
import { sign } from '@stablelib/ed25519' | ||
import { Signer } from '../JWT' | ||
import { bytesToBase64url, stringToBytes } from '../util' | ||
import { bytesToBase64url, stringToBytes } from '../util.js' | ||
@@ -5,0 +5,0 @@ /** |
@@ -1,4 +0,4 @@ | ||
import { hexToBytes } from '../util' | ||
import { Signer } from '../JWT' | ||
import { ES256KSigner } from './ES256KSigner' | ||
import type { Signer } from '../JWT.js' | ||
import { hexToBytes } from '../util.js' | ||
import { ES256KSigner } from './ES256KSigner.js' | ||
@@ -5,0 +5,0 @@ /** |
@@ -1,6 +0,5 @@ | ||
import { leftpad } from '../util' | ||
import { toJose } from '../util' | ||
import { Signer } from '../JWT' | ||
import { sha256 } from '../Digest' | ||
import elliptic from 'elliptic' | ||
import type { Signer } from '../JWT.js' | ||
import { leftpad, toJose } from '../util.js' | ||
import { sha256 } from '../Digest.js' | ||
@@ -37,3 +36,3 @@ const secp256k1 = new elliptic.ec('secp256k1') | ||
s: leftpad(s.toString('hex')), | ||
recoveryParam, | ||
recoveryParam: recoveryParam ?? undefined, | ||
}, | ||
@@ -40,0 +39,0 @@ recoverable |
@@ -1,6 +0,5 @@ | ||
import { leftpad } from '../util' | ||
import { toJose } from '../util' | ||
import { Signer } from '../JWT' | ||
import { sha256 } from '../Digest' | ||
import elliptic from 'elliptic' | ||
import { leftpad, toJose } from '../util.js' | ||
import type { Signer } from '../JWT.js' | ||
import { sha256 } from '../Digest.js' | ||
@@ -7,0 +6,0 @@ const secp256r1 = new elliptic.ec('p256') |
@@ -1,4 +0,4 @@ | ||
import { EdDSASigner as EdDSASigner } from './EdDSASigner' | ||
import { Signer } from '../JWT' | ||
import { base64ToBytes } from '../util' | ||
import { EdDSASigner as EdDSASigner } from './EdDSASigner.js' | ||
import type { Signer } from '../JWT.js' | ||
import { base64ToBytes } from '../util.js' | ||
@@ -10,3 +10,4 @@ /** | ||
* | ||
* The signing function itself takes the data as a `string` or `Uint8Array` parameter and returns a `base64Url`-encoded signature. | ||
* The signing function itself takes the data as a `string` or `Uint8Array` parameter and returns a | ||
* `base64Url`-encoded signature. | ||
* | ||
@@ -13,0 +14,0 @@ * @example |
@@ -1,4 +0,4 @@ | ||
import { fromJose, hexToBytes } from '../util' | ||
import { Signer } from '../JWT' | ||
import { ES256KSigner } from './ES256KSigner' | ||
import { fromJose, hexToBytes } from '../util.js' | ||
import type { Signer } from '../JWT.js' | ||
import { ES256KSigner } from './ES256KSigner.js' | ||
@@ -5,0 +5,0 @@ /** |
@@ -1,4 +0,6 @@ | ||
import * as u8a from 'uint8arrays' | ||
import { concat, fromString, toString } from 'uint8arrays' | ||
import { bases } from 'multiformats/basics' | ||
const u8a = { toString, fromString, concat } | ||
/** | ||
@@ -10,3 +12,3 @@ * @deprecated Signers will be expected to return base64url `string` signatures. | ||
s: string | ||
recoveryParam?: number | null | ||
recoveryParam?: number | ||
} | ||
@@ -13,0 +15,0 @@ |
@@ -0,9 +1,11 @@ | ||
// noinspection ES6PreferShortImport | ||
import type { SignatureInput } from 'elliptic' | ||
import elliptic from 'elliptic' | ||
import { sha256, toEthereumAddress } from './Digest' | ||
import { verify } from '@stablelib/ed25519' | ||
import type { VerificationMethod } from 'did-resolver' | ||
import { bases } from 'multiformats/basics' | ||
import { hexToBytes, base58ToBytes, base64ToBytes, bytesToHex, EcdsaSignature, stringToBytes } from './util' | ||
import { verifyBlockchainAccountId } from './blockchains' | ||
import { sha256, toEthereumAddress } from './Digest.js' | ||
import { base58ToBytes, base64ToBytes, bytesToHex, EcdsaSignature, hexToBytes, stringToBytes } from './util.js' | ||
import { verifyBlockchainAccountId } from './blockchains/index.js' | ||
@@ -10,0 +12,0 @@ const secp256k1 = new elliptic.ec('secp256k1') |
@@ -0,10 +1,10 @@ | ||
import type { Resolvable, VerificationMethod } from 'did-resolver' | ||
import { XChaCha20Poly1305 } from '@stablelib/xchacha20poly1305' | ||
import { generateKeyPair, sharedKey } from '@stablelib/x25519' | ||
import { randomBytes } from '@stablelib/random' | ||
import { concatKDF } from './Digest' | ||
import { bytesToBase64url, base58ToBytes, encodeBase64url, toSealed, base64ToBytes } from './util' | ||
import { Recipient, EncryptionResult, Encrypter, Decrypter, ProtectedHeader } from './JWE' | ||
import type { VerificationMethod, Resolvable } from 'did-resolver' | ||
import { ECDH } from './ECDH' | ||
import { fromString } from 'uint8arrays/from-string' | ||
import { fromString } from 'uint8arrays' | ||
import { concatKDF } from './Digest.js' | ||
import { base58ToBytes, base64ToBytes, bytesToBase64url, encodeBase64url, toSealed } from './util.js' | ||
import { Decrypter, Encrypter, EncryptionResult, ProtectedHeader, Recipient } from './JWE.js' | ||
import { ECDH } from './ECDH.js' | ||
@@ -143,2 +143,3 @@ /** | ||
const alg = 'dir' | ||
async function encrypt( | ||
@@ -150,3 +151,3 @@ cleartext: Uint8Array, | ||
const protHeader = encodeBase64url(JSON.stringify(Object.assign({ alg }, protectedHeader, { enc }))) | ||
const encodedAad = fromString(aad ? `${protHeader}.${bytesToBase64url(aad)}` : protHeader) | ||
const encodedAad = fromString(aad ? `${protHeader}.${bytesToBase64url(aad)}` : protHeader, 'utf-8') | ||
return { | ||
@@ -157,2 +158,3 @@ ...xc20pEncrypt(cleartext, encodedAad), | ||
} | ||
return { alg, enc, encrypt } | ||
@@ -163,5 +165,7 @@ } | ||
const cipher = new XChaCha20Poly1305(key) | ||
async function decrypt(sealed: Uint8Array, iv: Uint8Array, aad?: Uint8Array): Promise<Uint8Array | null> { | ||
return cipher.open(iv, sealed, aad) | ||
} | ||
return { alg: 'dir', enc: 'XC20P', decrypt } | ||
@@ -174,2 +178,3 @@ } | ||
const crv = 'X25519' | ||
async function encryptCek(cek: Uint8Array): Promise<Recipient> { | ||
@@ -193,2 +198,3 @@ const epk = generateKeyPair() | ||
} | ||
async function encrypt( | ||
@@ -209,2 +215,3 @@ cleartext: Uint8Array, | ||
} | ||
return { alg, enc: 'XC20P', encrypt, encryptCek } | ||
@@ -268,2 +275,3 @@ } | ||
} | ||
async function encrypt( | ||
@@ -284,2 +292,3 @@ cleartext: Uint8Array, | ||
} | ||
return { alg, enc: 'XC20P', encrypt, encryptCek } | ||
@@ -350,2 +359,3 @@ } | ||
const crv = 'X25519' | ||
async function decrypt( | ||
@@ -377,2 +387,3 @@ sealed: Uint8Array, | ||
} | ||
return { alg, enc: 'XC20P', decrypt } | ||
@@ -393,2 +404,3 @@ } | ||
const crv = 'X25519' | ||
async function decrypt( | ||
@@ -435,3 +447,4 @@ sealed: Uint8Array, | ||
} | ||
return { alg, enc: 'XC20P', decrypt } | ||
} |
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
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 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
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
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
12597
1192796
33
2
+ Addedmultiformats@11.0.212.1.3(transitive)
+ Addeduint8arrays@4.0.10(transitive)
- Removedmultiformats@9.9.0(transitive)
- Removeduint8arrays@3.1.1(transitive)
Updated@stablelib/ed25519@^1.0.3
Updated@stablelib/random@^1.0.2
Updated@stablelib/x25519@^1.0.3
Updateddid-resolver@^4.1.0
Updatedmultiformats@^11.0.2
Updateduint8arrays@^4.0.3