mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 06:29:28 -07:00
feat: minor tweaks
This commit is contained in:
parent
c3f7df2113
commit
a8a97b2d85
6 changed files with 55 additions and 64 deletions
11
package.json
11
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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -169,6 +169,7 @@ export const PublicKeyType = {
|
|||
EDDSA: 'eddsa',
|
||||
ES256: 'es256',
|
||||
OPENPGP: 'openpgp',
|
||||
UNKNOWN: 'unknown',
|
||||
NONE: 'none'
|
||||
}
|
||||
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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)'
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue