feat: minor tweaks

This commit is contained in:
Yarmo Mackenbach 2023-07-13 10:40:35 +02:00
parent c3f7df2113
commit a8a97b2d85
No known key found for this signature in database
GPG key ID: 3C57D093219103A3
6 changed files with 55 additions and 64 deletions

View file

@ -1,21 +1,18 @@
{ {
"name": "doipjs", "name": "doipjs",
"version": "0.19.1-alpha.0", "version": "1.0.0-rc.14",
"description": "Decentralized Online Identity Proofs library in Node.js", "description": "Decentralized Online Identity Proofs library in Node.js",
"type": "module", "type": "module",
"main": "./src/index.js", "main": "./src/index.js",
"exports": { "exports": {
".": { ".": {
"node": "./src/index.js", "default": "./src/index.js"
"default": "./dist/doip.core.js"
}, },
"./fetchers": { "./fetchers": {
"node": "./src/fetcher/index.js", "default": "./src/fetcher/index.js"
"default": "./dist/doip.fetchers.js"
}, },
"./fetchers-minimal": { "./fetchers-minimal": {
"node": "./src/fetcher/index.minimal.js", "default": "./src/fetcher/index.minimal.js"
"default": "./dist/doip.fetchers.minimal.js"
} }
}, },
"packageManager": "yarn@1.22.19", "packageManager": "yarn@1.22.19",

View file

@ -21,6 +21,7 @@ import { run } from './verifications.js'
import { list, data as _data } from './serviceProviders/index.js' import { list, data as _data } from './serviceProviders/index.js'
import { opts as _opts } from './defaults.js' import { opts as _opts } from './defaults.js'
import { ClaimStatus } from './enums.js' import { ClaimStatus } from './enums.js'
import { ServiceProvider } from './serviceProvider.js'
/** /**
* @class * @class
@ -362,7 +363,7 @@ function importJsonClaimVersion1 (claimObject) {
claim._uri = claimObject.uri claim._uri = claimObject.uri
claim._fingerprint = claimObject.fingerprint claim._fingerprint = claimObject.fingerprint
claim._matches = claimObject.matches claim._matches = claimObject.matches.map(x => new ServiceProvider(x))
if (claimObject.status === 'init') { if (claimObject.status === 'init') {
claim._status = 100 claim._status = 100
@ -403,7 +404,7 @@ function importJsonClaimVersion2 (claimObject) {
claim._uri = claimObject.uri claim._uri = claimObject.uri
claim._fingerprint = claimObject.proofs[0] claim._fingerprint = claimObject.proofs[0]
claim._matches = claimObject.matches claim._matches = claimObject.matches.map(x => new ServiceProvider(x))
claim._status = claimObject.status claim._status = claimObject.status
return claim return claim

View file

@ -169,6 +169,7 @@ export const PublicKeyType = {
EDDSA: 'eddsa', EDDSA: 'eddsa',
ES256: 'es256', ES256: 'es256',
OPENPGP: 'openpgp', OPENPGP: 'openpgp',
UNKNOWN: 'unknown',
NONE: 'none' NONE: 'none'
} }

View file

@ -77,6 +77,12 @@ export class Profile {
* @public * @public
*/ */
keyType: PublicKeyType.NONE, keyType: PublicKeyType.NONE,
/**
* The fingerprint of the cryptographic key
* @type {string | null}
* @public
*/
fingerprint: null,
/** /**
* The encoding of the cryptographic key * The encoding of the cryptographic key
* @type {PublicKeyEncoding} * @type {PublicKeyEncoding}
@ -91,7 +97,7 @@ export class Profile {
encodedKey: null, encodedKey: null,
/** /**
* The raw cryptographic key as object (to be removed during toJSON()) * 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 * @public
*/ */
key: null, key: null,
@ -138,18 +144,6 @@ export class Profile {
this.verifiers.push({ name, url }) 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 * Get a JSON representation of the Profile object
* @function * @function
@ -164,6 +158,7 @@ export class Profile {
primaryPersonaIndex: this.primaryPersonaIndex, primaryPersonaIndex: this.primaryPersonaIndex,
publicKey: { publicKey: {
keyType: this.publicKey.keyType, keyType: this.publicKey.keyType,
fingerprint: this.publicKey.fingerprint,
encoding: this.publicKey.encoding, encoding: this.publicKey.encoding,
encodedKey: this.publicKey.encodedKey, encodedKey: this.publicKey.encodedKey,
fetch: { fetch: {

View file

@ -17,7 +17,6 @@ import { expect, use } from 'chai'
import chaiAsPromised from 'chai-as-promised' import chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised) use(chaiAsPromised)
import { PublicKey } from 'openpgp'
import { openpgp, Profile } from '../src/index.js' import { openpgp, Profile } from '../src/index.js'
const pubKeyFingerprint = "3637202523e7c1309ab79e99ef2dc5827b445f4b" const pubKeyFingerprint = "3637202523e7c1309ab79e99ef2dc5827b445f4b"
@ -172,33 +171,28 @@ describe('openpgp.fetchPlaintext', () => {
}).timeout('12s') }).timeout('12s')
}) })
// describe('openpgp.process', () => { describe('openpgp.parsePublicKey', () => {
// it('should be a function (1 argument)', () => { it('should be a function (1 argument)', () => {
// expect(openpgp.process).to.be.a('function') expect(openpgp.parsePublicKey).to.be.a('function')
// expect(openpgp.process).to.have.length(1) expect(openpgp.parsePublicKey).to.have.length(1)
// }) })
// it('should return an object with specific openpgp', async () => { it('should return an object with specific openpgp', async () => {
// const pubKey = await openpgp.fetchPlaintext(pubKeyPlaintext) const pubKey = await openpgp.fetchPlaintext(pubKeyPlaintext)
// const obj = await openpgp.process(pubKey) const profile = await openpgp.parsePublicKey(pubKey.publicKey.key)
// expect(obj).to.have.openpgp([ expect(profile).to.be.instanceOf(Profile)
// 'users', })
// 'fingerprint', it('should ignore non-proof notations', async () => {
// 'primaryUserIndex', const pubKey = await openpgp.fetchPlaintext(pubKeyWithOtherNotations)
// 'key', const profile = await openpgp.parsePublicKey(pubKey.publicKey.key)
// ]) expect(profile.personas).to.be.lengthOf(1)
// }) expect(profile.personas[0].claims).to.be.lengthOf(1)
// it('should ignore non-proof notations', async () => { expect(profile.personas[0].claims[0].uri).to.be.equal('dns:yarmo.eu?type=TXT')
// const pubKey = await openpgp.fetchPlaintext(pubKeyWithOtherNotations) })
// const obj = await openpgp.process(pubKey) it('should properly handle revoked UIDs', async () => {
// expect(obj.users).to.be.lengthOf(1) const pubKey = await openpgp.fetchPlaintext(pubKeyWithRevokedUID)
// expect(obj.users[0].claims).to.be.lengthOf(1) const profile = await openpgp.parsePublicKey(pubKey.publicKey.key)
// expect(obj.users[0].claims[0].uri).to.be.equal('dns:yarmo.eu?type=TXT') expect(profile.personas).to.be.lengthOf(2)
// }) expect(profile.personas[0].isRevoked).to.be.true
// it('should properly handle revoked UIDs', async () => { expect(profile.personas[1].isRevoked).to.be.false
// 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
// })
// })

View file

@ -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 See the License for the specific language governing permissions and
limitations under the License. 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----- const sigProfile = `-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512 Hash: SHA512
@ -80,28 +82,29 @@ YCKJPotiqe50nBijHHbuABtBianiMZOm2BbaPnsmdHIX5ynWhOI8LHR1CVmTI/0o
=2vuM =2vuM
-----END PGP SIGNATURE-----` -----END PGP SIGNATURE-----`
describe('signatures.process', () => { describe('signatures.parse', () => {
it('should be a function (2 arguments)', () => { it('should be a function (2 arguments)', () => {
expect(signatures.process).to.be.a('function') expect(signatures.parse).to.be.a('function')
expect(signatures.process).to.have.length(1) expect(signatures.parse).to.have.length(1)
}) })
it('should verify a valid signature', async () => { it('should verify a valid signature', async () => {
const verification = await signatures.process(sigProfile) const profile = await signatures.parse(sigProfile)
expect(verification.fingerprint).to.be.equal( expect(profile).to.be.instanceOf(Profile)
'3637202523e7c1309ab79e99ef2dc5827b445f4b' 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 () => { it('should reject an invalid signature', async () => {
return expect( return expect(
signatures.process(invalidSigProfileMessage) signatures.parse(invalidSigProfileMessage)
).to.eventually.be.rejectedWith( ).to.eventually.be.rejectedWith(
'Signature could not be verified (Signed digest did not match)' 'Signature could not be verified (Signed digest did not match)'
) )
}) })
it('should reject an invalid signature', async () => { it('should reject an invalid signature', async () => {
return expect( return expect(
signatures.process(invalidSigProfileHash) signatures.parse(invalidSigProfileHash)
).to.eventually.be.rejectedWith( ).to.eventually.be.rejectedWith(
'Signature could not be read (Ascii armor integrity check failed)' 'Signature could not be read (Ascii armor integrity check failed)'
) )