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

Commit e7f6296

Browse files
authored
Merge pull request #6 from PayString/nh/jose-3-update
Update to use jose 3.5.0 and paystring/utils 2.0.0
2 parents 01119b1 + 28e4de2 commit e7f6296

17 files changed

+195
-116
lines changed

.eslintrc.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,19 @@ module.exports = {
2626
'@xpring-eng/eslint-config-base',
2727
],
2828

29-
rules: {},
29+
rules: {
30+
// linter doesn't seem to understand ESM imports used by jose, even though typescript handles them just fine.
31+
"node/no-missing-import": ["error", {
32+
allowModules: ["jose"],
33+
}],
34+
"import/no-unresolved": [
35+
2,
36+
{
37+
ignore: [
38+
'jose'
39+
]
40+
}],
41+
},
3042
overrides: [
3143
{
3244
"files": ["*cli.ts"],

package-lock.json

Lines changed: 43 additions & 24 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@paystring/paystring-cli",
3-
"version": "1.1.0",
3+
"version": "2.0.0",
44
"description": "CLI for PayString",
55
"homepage": "https://github.com/paystring/paystring-cli#readme",
66
"bugs": {
@@ -28,11 +28,11 @@
2828
"test": "nyc mocha 'test/**/*.test.ts'"
2929
},
3030
"dependencies": {
31-
"@paystring/utils": "^1.3.0",
31+
"@paystring/utils": "^2.0.0",
3232
"axios": "^0.19.2",
3333
"beautify-json": "^1.0.1",
34-
"jose": "^1.27.3",
35-
"node-forge": "^0.10.0",
34+
"ec-key": "0.0.4",
35+
"jose": "^3.5.0",
3636
"vorpal": "^1.12.0"
3737
},
3838
"devDependencies": {

src/commands/key-generate.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { JWK } from 'jose'
1+
import { generateNewKey } from '@paystring/utils'
22

33
import Command from './Command'
44
import { writeFile } from './files'
5+
import { jwkToPem } from './pem-utils'
56

67
/**
78
* Generates an identity key, loads the key into local storage and saves the key
@@ -12,16 +13,16 @@ export default class GenerateIdentityKeyCommand extends Command {
1213
* @override
1314
*/
1415
protected async action(): Promise<void> {
15-
const key = await JWK.generate('EC', 'P-256')
16-
const pem = key.toPEM(true)
16+
const key = await generateNewKey()
17+
const pem = jwkToPem(key)
1718
try {
1819
const filename = await writeFile('./identity-key.pem', pem)
1920
this.vorpal.log(`wrote key to ${filename}`)
2021
} catch {
2122
this.vorpal.log('failed to write key, outputting instead')
2223
this.vorpal.log(pem)
2324
}
24-
this.localStorage.addSigningKey('identity-keys', key.toJWK(true))
25+
this.localStorage.addSigningKey('identity-keys', key)
2526
}
2627

2728
/**

src/commands/key-load.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { getSigningKeyFromFile } from '@paystring/utils'
21
import * as Vorpal from 'vorpal'
32

43
import Command from './Command'
4+
import { getSigningKeyFromFile } from './pem-utils'
55

66
/**
77
* Loads an identity key from a PEM file.
@@ -17,7 +17,7 @@ export default class LoadIdentityKeyCommand extends Command {
1717
this.vorpal.log(`loading identity-key from ${filePath}`)
1818
const key = await getSigningKeyFromFile(filePath)
1919
this.vorpal.log(`loaded identity-key from ${filePath}. Sign away.`)
20-
this.localStorage.addSigningKey('identity-keys', key.toJWK(true))
20+
this.localStorage.addSigningKey('identity-keys', key)
2121
}
2222

2323
/**

src/commands/keys-list.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ export default class ListKeysCommand extends Command {
3535
const keys = this.localStorage.getSigningKeys(name)
3636
keys.forEach((key) => {
3737
const kid = key.kid ?? 'not set'
38-
if ('crv' in key) {
39-
this.vorpal.log(`${name}: type=${key.kty}, type=${key.crv}, id=${kid}`)
38+
const kty = key.kty ?? 'not set'
39+
if (typeof key.crv === 'string') {
40+
this.vorpal.log(`${name}: type=${kty}, type=${key.crv}, id=${kid}`)
4041
} else {
41-
this.vorpal.log(`${name}: type=${key.kty}, id=${kid}`)
42+
this.vorpal.log(`${name}: type=${kty}, id=${kid}`)
4243
}
4344
})
4445
}

src/commands/keys-print.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { toKey } from '@paystring/utils'
2-
31
import Command from './Command'
2+
import { jwkToPem } from './pem-utils'
43

54
/**
65
* Prints, to console, a summary of the identity and server keys that are currently loaded in
@@ -36,7 +35,7 @@ export default class PrintKeysCommand extends Command {
3635
private printKeys(name: string): void {
3736
const keys = this.localStorage.getSigningKeys(name)
3837
keys.forEach((key) => {
39-
const pem = toKey(key).toPEM(true)
38+
const pem = jwkToPem(key)
4039
this.vorpal.log(pem)
4140
})
4241
}

src/commands/localstorage.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PaymentInformation } from '@paystring/utils'
2-
import { JWKECKey, JWKOctKey, JWKOKPKey, JWKRSAKey } from 'jose'
2+
import { JWK } from 'jose/webcrypto/types'
33
import * as Vorpal from 'vorpal'
44

55
/**
@@ -53,12 +53,10 @@ export default class LocalStorage {
5353
* @param name - The name of the key.
5454
* @returns The key or null.
5555
*/
56-
public getSigningKeys(
57-
name: string,
58-
): Array<JWKRSAKey | JWKECKey | JWKOKPKey | JWKOctKey> {
56+
public getSigningKeys(name: string): JWK[] {
5957
const existing = this.getItem(name)
6058
if (existing) {
61-
return existing as Array<JWKRSAKey | JWKECKey | JWKOKPKey | JWKOctKey>
59+
return existing as JWK[]
6260
}
6361
return []
6462
}
@@ -70,10 +68,7 @@ export default class LocalStorage {
7068
* @param name - The name of the key.
7169
* @param key - The key to store.
7270
*/
73-
public addSigningKey(
74-
name: string,
75-
key: JWKRSAKey | JWKECKey | JWKOKPKey | JWKOctKey,
76-
): void {
71+
public addSigningKey(name: string, key: JWK): void {
7772
const keys = this.getSigningKeys(name)
7873
const updated = keys.concat(key)
7974
this.setItem(name, JSON.stringify(updated))
@@ -94,12 +89,7 @@ export default class LocalStorage {
9489
* @param name - The name of the item to get.
9590
* @returns The object or undefined if not in localstore.
9691
*/
97-
private getItem(
98-
name: string,
99-
):
100-
| Array<JWKRSAKey | JWKECKey | JWKOKPKey | JWKOctKey>
101-
| PaymentInformation
102-
| undefined {
92+
private getItem(name: string): JWK[] | PaymentInformation | undefined {
10393
const rawValue = this.localStorage.getItem(name)
10494
if (rawValue && typeof rawValue === 'string') {
10595
try {

src/commands/paystring-inspect.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class InspectPayStringCommand extends Command {
4444
*/
4545
protected async action(args: Vorpal.Args): Promise<void> {
4646
const info = await this.payStringFromArgsOrLocalStorage(args)
47-
const result = this.paymentInformationInspector.inspect(info)
47+
const result = await this.paymentInformationInspector.inspect(info)
4848
this.vorpal.log(`${info.payId} ${validString(result.isVerified)}`)
4949
result.verifiedAddressesResults.forEach((addressResult) => {
5050
const address = addressResult.address
@@ -83,9 +83,10 @@ export default class InspectPayStringCommand extends Command {
8383
)}`,
8484
)
8585
if (signatureResult.jwk && signatureResult.keyType) {
86-
const thumbprint = signatureResult.jwk.thumbprint
86+
const thumbprint = signatureResult.jwk.kid ?? 'not set'
87+
const kty = signatureResult.jwk.kty ?? 'no key type'
8788
this.vorpal.log(
88-
` - Signed with ${signatureResult.jwk.kty} ${signatureResult.keyType} with thumbprint ${thumbprint}`,
89+
` - Signed with ${kty} ${signatureResult.keyType} with thumbprint ${thumbprint}`,
8990
)
9091
}
9192
}

0 commit comments

Comments
 (0)