From a8a97b2d85b926904e875efcba6c6e727cd12924 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Thu, 13 Jul 2023 10:40:35 +0200 Subject: [PATCH] feat: minor tweaks --- package.json | 11 +++----- src/claim.js | 5 ++-- src/enums.js | 1 + src/profile.js | 21 ++++++---------- test/openpgp.test.js | 56 ++++++++++++++++++----------------------- test/signatures.test.js | 25 ++++++++++-------- 6 files changed, 55 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index cc6d969..39f81b7 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,18 @@ { "name": "doipjs", - "version": "0.19.1-alpha.0", + "version": "1.0.0-rc.14", "description": "Decentralized Online Identity Proofs library in Node.js", "type": "module", "main": "./src/index.js", "exports": { ".": { - "node": "./src/index.js", - "default": "./dist/doip.core.js" + "default": "./src/index.js" }, "./fetchers": { - "node": "./src/fetcher/index.js", - "default": "./dist/doip.fetchers.js" + "default": "./src/fetcher/index.js" }, "./fetchers-minimal": { - "node": "./src/fetcher/index.minimal.js", - "default": "./dist/doip.fetchers.minimal.js" + "default": "./src/fetcher/index.minimal.js" } }, "packageManager": "yarn@1.22.19", diff --git a/src/claim.js b/src/claim.js index 29e3439..8765a94 100644 --- a/src/claim.js +++ b/src/claim.js @@ -21,6 +21,7 @@ import { run } from './verifications.js' import { list, data as _data } from './serviceProviders/index.js' import { opts as _opts } from './defaults.js' import { ClaimStatus } from './enums.js' +import { ServiceProvider } from './serviceProvider.js' /** * @class @@ -362,7 +363,7 @@ function importJsonClaimVersion1 (claimObject) { claim._uri = claimObject.uri claim._fingerprint = claimObject.fingerprint - claim._matches = claimObject.matches + claim._matches = claimObject.matches.map(x => new ServiceProvider(x)) if (claimObject.status === 'init') { claim._status = 100 @@ -403,7 +404,7 @@ function importJsonClaimVersion2 (claimObject) { claim._uri = claimObject.uri claim._fingerprint = claimObject.proofs[0] - claim._matches = claimObject.matches + claim._matches = claimObject.matches.map(x => new ServiceProvider(x)) claim._status = claimObject.status return claim diff --git a/src/enums.js b/src/enums.js index 915ecba..e6afc24 100644 --- a/src/enums.js +++ b/src/enums.js @@ -169,6 +169,7 @@ export const PublicKeyType = { EDDSA: 'eddsa', ES256: 'es256', OPENPGP: 'openpgp', + UNKNOWN: 'unknown', NONE: 'none' } diff --git a/src/profile.js b/src/profile.js index cc74a69..a5b0846 100644 --- a/src/profile.js +++ b/src/profile.js @@ -77,6 +77,12 @@ export class Profile { * @public */ keyType: PublicKeyType.NONE, + /** + * The fingerprint of the cryptographic key + * @type {string | null} + * @public + */ + fingerprint: null, /** * The encoding of the cryptographic key * @type {PublicKeyEncoding} @@ -91,7 +97,7 @@ export class Profile { encodedKey: null, /** * The raw cryptographic key as object (to be removed during toJSON()) - * @type {import('openpgp').PublicKey | import('jose').KeyLike | null} + * @type {import('openpgp').PublicKey | import('jose').JWK | null} * @public */ key: null, @@ -138,18 +144,6 @@ export class Profile { this.verifiers.push({ name, url }) } - /** - * @function - * @param {import('openpgp').PublicKey} publicKey - */ - setOpenPgpPublicKey (publicKey) {} - - /** - * @function - * @param {import('jose').KeyLike} publicKey - */ - setJwkPublicKey (publicKey) {} - /** * Get a JSON representation of the Profile object * @function @@ -164,6 +158,7 @@ export class Profile { primaryPersonaIndex: this.primaryPersonaIndex, publicKey: { keyType: this.publicKey.keyType, + fingerprint: this.publicKey.fingerprint, encoding: this.publicKey.encoding, encodedKey: this.publicKey.encodedKey, fetch: { diff --git a/test/openpgp.test.js b/test/openpgp.test.js index 796ceed..6ac43fd 100644 --- a/test/openpgp.test.js +++ b/test/openpgp.test.js @@ -17,7 +17,6 @@ import { expect, use } from 'chai' import chaiAsPromised from 'chai-as-promised' use(chaiAsPromised) -import { PublicKey } from 'openpgp' import { openpgp, Profile } from '../src/index.js' const pubKeyFingerprint = "3637202523e7c1309ab79e99ef2dc5827b445f4b" @@ -172,33 +171,28 @@ describe('openpgp.fetchPlaintext', () => { }).timeout('12s') }) -// describe('openpgp.process', () => { -// it('should be a function (1 argument)', () => { -// expect(openpgp.process).to.be.a('function') -// expect(openpgp.process).to.have.length(1) -// }) -// it('should return an object with specific openpgp', async () => { -// const pubKey = await openpgp.fetchPlaintext(pubKeyPlaintext) -// const obj = await openpgp.process(pubKey) -// expect(obj).to.have.openpgp([ -// 'users', -// 'fingerprint', -// 'primaryUserIndex', -// 'key', -// ]) -// }) -// it('should ignore non-proof notations', async () => { -// const pubKey = await openpgp.fetchPlaintext(pubKeyWithOtherNotations) -// const obj = await openpgp.process(pubKey) -// expect(obj.users).to.be.lengthOf(1) -// expect(obj.users[0].claims).to.be.lengthOf(1) -// expect(obj.users[0].claims[0].uri).to.be.equal('dns:yarmo.eu?type=TXT') -// }) -// it('should properly handle revoked UIDs', async () => { -// const pubKey = await openpgp.fetchPlaintext(pubKeyWithRevokedUID) -// const obj = await openpgp.process(pubKey) -// expect(obj.users).to.be.lengthOf(2) -// expect(obj.users[0].userData.isRevoked).to.be.true -// expect(obj.users[1].userData.isRevoked).to.be.false -// }) -// }) +describe('openpgp.parsePublicKey', () => { + it('should be a function (1 argument)', () => { + expect(openpgp.parsePublicKey).to.be.a('function') + expect(openpgp.parsePublicKey).to.have.length(1) + }) + it('should return an object with specific openpgp', async () => { + const pubKey = await openpgp.fetchPlaintext(pubKeyPlaintext) + const profile = await openpgp.parsePublicKey(pubKey.publicKey.key) + expect(profile).to.be.instanceOf(Profile) + }) + it('should ignore non-proof notations', async () => { + const pubKey = await openpgp.fetchPlaintext(pubKeyWithOtherNotations) + const profile = await openpgp.parsePublicKey(pubKey.publicKey.key) + expect(profile.personas).to.be.lengthOf(1) + expect(profile.personas[0].claims).to.be.lengthOf(1) + expect(profile.personas[0].claims[0].uri).to.be.equal('dns:yarmo.eu?type=TXT') + }) + it('should properly handle revoked UIDs', async () => { + const pubKey = await openpgp.fetchPlaintext(pubKeyWithRevokedUID) + const profile = await openpgp.parsePublicKey(pubKey.publicKey.key) + expect(profile.personas).to.be.lengthOf(2) + expect(profile.personas[0].isRevoked).to.be.true + expect(profile.personas[1].isRevoked).to.be.false + }) +}) diff --git a/test/signatures.test.js b/test/signatures.test.js index 0c1a4e1..9190d1a 100644 --- a/test/signatures.test.js +++ b/test/signatures.test.js @@ -13,9 +13,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import { expect } from 'chai' +import { expect, use } from 'chai' +import chaiAsPromised from 'chai-as-promised' +use(chaiAsPromised) -import { signatures } from '../src/index.js' +import { Profile, signatures } from '../src/index.js' const sigProfile = `-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 @@ -80,28 +82,29 @@ YCKJPotiqe50nBijHHbuABtBianiMZOm2BbaPnsmdHIX5ynWhOI8LHR1CVmTI/0o =2vuM -----END PGP SIGNATURE-----` -describe('signatures.process', () => { +describe('signatures.parse', () => { it('should be a function (2 arguments)', () => { - expect(signatures.process).to.be.a('function') - expect(signatures.process).to.have.length(1) + expect(signatures.parse).to.be.a('function') + expect(signatures.parse).to.have.length(1) }) it('should verify a valid signature', async () => { - const verification = await signatures.process(sigProfile) - expect(verification.fingerprint).to.be.equal( - '3637202523e7c1309ab79e99ef2dc5827b445f4b' + const profile = await signatures.parse(sigProfile) + expect(profile).to.be.instanceOf(Profile) + expect(profile.identifier).to.be.equal( + 'openpgp4fpr:3637202523e7c1309ab79e99ef2dc5827b445f4b' ) - expect(verification.users[0].claims).to.be.length(1) + expect(profile.personas[0].claims).to.be.length(1) }) it('should reject an invalid signature', async () => { return expect( - signatures.process(invalidSigProfileMessage) + signatures.parse(invalidSigProfileMessage) ).to.eventually.be.rejectedWith( 'Signature could not be verified (Signed digest did not match)' ) }) it('should reject an invalid signature', async () => { return expect( - signatures.process(invalidSigProfileHash) + signatures.parse(invalidSigProfileHash) ).to.eventually.be.rejectedWith( 'Signature could not be read (Ascii armor integrity check failed)' )