Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit fa4bb26

Browse files
authored
Verifiable addresses (#17)
* functions and types for signing and validating a VerifiablePayID * get pem and x5c working simplify verify call to use Embedded option * lint fixes and refactored SigningParams types from interface to classes * exports * packages.json cleanup
1 parent f7b9e77 commit fa4bb26

13 files changed

Lines changed: 550 additions & 71 deletions

package-lock.json

Lines changed: 37 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@
2323
"lintNoFix": "eslint . --ext .ts --max-warnings 0 && prettier --check '**/*.{md,json}'",
2424
"test": "nyc mocha 'test/**/*.test.ts'"
2525
},
26+
"dependencies": {
27+
"jose": "^1.27.2"
28+
},
2629
"devDependencies": {
2730
"@arkweid/lefthook": "^0.7.2",
2831
"@fintechstudios/eslint-plugin-chai-as-promised": "^3.0.2",
2932
"@types/chai": "^4.2.11",
3033
"@types/mocha": "^7.0.2",
3134
"@types/node": "^14.0.14",
35+
"@types/pem-jwk": "^1.5.0",
3236
"@typescript-eslint/eslint-plugin": "^3.7.1",
3337
"@typescript-eslint/parser": "^3.7.1",
3438
"@xpring-eng/eslint-config-base": "^0.11.0",

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './parse'
22
export * from './convert'
33
export * from './helpers'
4+
export * from './verifiable'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { JWK } from 'jose'
2+
3+
import { SigningParams } from './verifiable-payid'
4+
5+
import ECKey = JWK.ECKey
6+
import RSAKey = JWK.RSAKey
7+
import OctKey = JWK.OctKey
8+
import OKPKey = JWK.OKPKey
9+
10+
/**
11+
* Represents the properties needed to sign a PayID using an identity key.
12+
*/
13+
export default class IdentityKeySigningParams implements SigningParams {
14+
public readonly keyType = 'identityKey'
15+
public readonly key: ECKey | RSAKey | OctKey | OKPKey
16+
public readonly alg: string
17+
18+
/**
19+
* Default constructor.
20+
*
21+
* @param key - The private key to sign with.
22+
* @param alg - The signing algorithm.
23+
*/
24+
public constructor(key: ECKey | RSAKey | OctKey | OKPKey, alg: string) {
25+
this.key = key
26+
this.alg = alg
27+
}
28+
}

src/verifiable/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './signatures'
2+
export * from './verifiable-payid'

src/verifiable/keys.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { promises } from 'fs'
2+
3+
import { JWK } from 'jose'
4+
5+
import RSAKey = JWK.RSAKey
6+
import ECKey = JWK.ECKey
7+
import OKPKey = JWK.OKPKey
8+
import OctKey = JWK.OctKey
9+
10+
/**
11+
* Reads JWK key from a file.
12+
*
13+
* @param path - The full file path of the key file.
14+
* @returns A JWK key.
15+
*/
16+
export default async function getKeyFromFile(
17+
path: string,
18+
): Promise<RSAKey | ECKey | OKPKey | OctKey> {
19+
const pem = await promises.readFile(path, 'ascii')
20+
return JWK.asKey(pem)
21+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { JWK } from 'jose'
2+
3+
import { SigningParams } from './verifiable-payid'
4+
5+
import ECKey = JWK.ECKey
6+
import RSAKey = JWK.RSAKey
7+
import OctKey = JWK.OctKey
8+
import OKPKey = JWK.OKPKey
9+
10+
/**
11+
* Represents the properties needed to sign a PayID using a server key.
12+
*/
13+
export default class ServerKeySigningParams implements SigningParams {
14+
public readonly keyType = 'serverKey'
15+
public readonly key: ECKey | RSAKey | OctKey | OKPKey
16+
public readonly alg: string
17+
public readonly x5c: ECKey | RSAKey | OctKey | OKPKey
18+
19+
/**
20+
* Default constructor.
21+
*
22+
* @param key - The private key to sign with.
23+
* @param alg - The signing algorithm.
24+
* @param x5c - The public x509 certificate.
25+
*/
26+
public constructor(
27+
key: ECKey | RSAKey | OctKey | OKPKey,
28+
alg: string,
29+
x5c: ECKey | RSAKey | OctKey | OKPKey,
30+
) {
31+
this.key = key
32+
this.alg = alg
33+
this.x5c = x5c
34+
}
35+
}

0 commit comments

Comments
 (0)