chore: release 1.1.0

This commit is contained in:
Yarmo Mackenbach 2023-09-21 14:49:15 +02:00
parent cb397e42b7
commit 9c9b387fc9
No known key found for this signature in database
GPG key ID: 3C57D093219103A3
9 changed files with 427 additions and 322 deletions

View file

@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.1.0] - 2023-09-21
### Changed
- Unify fromJSON() for Profile, Persona and Claim classes
## [1.0.4] - 2023-09-19
### Fixed
- Allow the activitypub Person request to fail

729
dist/doip.core.js vendored
View file

@ -236,318 +236,6 @@ var doip = (function (exports, openpgp$1, fetcher) {
PublicKeyType: PublicKeyType
});
/*
Copyright 2023 Yarmo Mackenbach
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.
*/
/**
* A profile of personas with identity claims
* @function
* @param {Array<import('./persona.js').Persona>} personas
* @public
* @example
* const claim = Claim('https://alice.tld', '123');
* const pers = Persona('Alice', 'About Alice', [claim]);
* const profile = Profile([pers]);
*/
class Profile {
/**
* Create a new profile
* @function
* @param {import('./enums.js').ProfileType} profileType
* @param {string} identifier
* @param {Array<import('./persona.js').Persona>} personas
* @public
*/
constructor (profileType, identifier, personas) {
/**
* Profile version
* @type {number}
* @public
*/
this.profileVersion = 2;
/**
* Profile version
* @type {import('./enums.js').ProfileType}
* @public
*/
this.profileType = profileType;
/**
* Identifier of the profile (fingerprint, email address, uri...)
* @type {string}
* @public
*/
this.identifier = identifier;
/**
* List of personas
* @type {Array<import('./persona.js').Persona>}
* @public
*/
this.personas = personas || [];
/**
* Index of primary persona (to be displayed first or prominently)
* @type {number}
* @public
*/
this.primaryPersonaIndex = personas.length > 0 ? 0 : -1;
/**
* The cryptographic key associated with the profile
* @property {object}
* @public
*/
this.publicKey = {
/**
* The type of cryptographic key
* @type {PublicKeyType}
* @public
*/
keyType: PublicKeyType.NONE,
/**
* The fingerprint of the cryptographic key
* @type {string | null}
* @public
*/
fingerprint: null,
/**
* The encoding of the cryptographic key
* @type {PublicKeyEncoding}
* @public
*/
encoding: PublicKeyEncoding.NONE,
/**
* The encoded cryptographic key
* @type {string | null}
* @public
*/
encodedKey: null,
/**
* The raw cryptographic key as object (to be removed during toJSON())
* @type {import('openpgp').PublicKey | import('jose').JWK | null}
* @public
*/
key: null,
/**
* Details on how to fetch the public key
* @property {object}
* @public
*/
fetch: {
/**
* The method to fetch the key
* @type {PublicKeyFetchMethod}
* @public
*/
method: PublicKeyFetchMethod.NONE,
/**
* The query to fetch the key
* @type {string | null}
* @public
*/
query: null,
/**
* The URL the method eventually resolved to
* @type {string | null}
* @public
*/
resolvedUrl: null
}
};
/**
* List of verifier URLs
* @type {{name: string, url: string}[]}
* @public
*/
this.verifiers = [];
}
/**
* @function
* @param {string} name
* @param {string} url
*/
addVerifier (name, url) {
this.verifiers.push({ name, url });
}
/**
* Get a JSON representation of the Profile object
* @function
* @returns {object}
*/
toJSON () {
return {
profileVersion: this.profileVersion,
profileType: this.profileType,
identifier: this.identifier,
personas: this.personas.map(x => x.toJSON()),
primaryPersonaIndex: this.primaryPersonaIndex,
publicKey: {
keyType: this.publicKey.keyType,
fingerprint: this.publicKey.fingerprint,
encoding: this.publicKey.encoding,
encodedKey: this.publicKey.encodedKey,
fetch: {
method: this.publicKey.fetch.method,
query: this.publicKey.fetch.query,
resolvedUrl: this.publicKey.fetch.resolvedUrl
}
},
verifiers: this.verifiers
}
}
}
/*
Copyright 2023 Yarmo Mackenbach
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.
*/
/**
* A persona with identity claims
* @class
* @constructor
* @public
* @example
* const claim = Claim('https://alice.tld', '123');
* const pers = Persona('Alice', 'About Alice', [claim]);
*/
class Persona {
/**
* @param {string} name
* @param {import('./claim.js').Claim[]} claims
*/
constructor (name, claims) {
/**
* Identifier of the persona
* @type {string | null}
* @public
*/
this.identifier = null;
/**
* Name to be displayed on the profile page
* @type {string}
* @public
*/
this.name = name;
/**
* Email address of the persona
* @type {string | null}
* @public
*/
this.email = null;
/**
* Description to be displayed on the profile page
* @type {string | null}
* @public
*/
this.description = null;
/**
* URL to an avatar image
* @type {string | null}
* @public
*/
this.avatarUrl = null;
/**
* List of identity claims
* @type {import('./claim.js').Claim[]}
* @public
*/
this.claims = claims;
/**
* Has the persona been revoked
* @type {boolean}
* @public
*/
this.isRevoked = false;
}
/**
* @function
* @param {string} identifier
*/
setIdentifier (identifier) {
this.identifier = identifier;
}
/**
* @function
* @param {string} description
*/
setDescription (description) {
this.description = description;
}
/**
* @function
* @param {string} email
*/
setEmailAddress (email) {
this.email = email;
}
/**
* @function
* @param {string} avatarUrl
*/
setAvatarUrl (avatarUrl) {
this.avatarUrl = avatarUrl;
}
/**
* @function
* @param {import('./claim.js').Claim} claim
*/
addClaim (claim) {
this.claims.push(claim);
}
/**
* @function
*/
revoke () {
this.isRevoked = true;
}
/**
* Get a JSON representation of the Profile object
* @function
* @returns {object}
*/
toJSON () {
return {
identifier: this.identifier,
name: this.name,
email: this.email,
description: this.description,
avatarUrl: this.avatarUrl,
isRevoked: this.isRevoked,
claims: this.claims.map(x => x.toJSON())
}
}
}
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function getDefaultExportFromCjs (x) {
@ -5518,10 +5206,11 @@ var doip = (function (exports, openpgp$1, fetcher) {
/**
* @function
* @param {object} claimObject
* @returns {Claim | Error}
* @example
* const claimAlt = doip.Claim(JSON.stringify(claim));
* doip.Claim.fromJSON(JSON.stringify(claim));
*/
static fromJson (claimObject) {
static fromJSON (claimObject) {
/** @type {Claim} */
let claim;
let result;
@ -5849,6 +5538,418 @@ var doip = (function (exports, openpgp$1, fetcher) {
return claim
}
/*
Copyright 2023 Yarmo Mackenbach
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.
*/
/**
* A persona with identity claims
* @class
* @constructor
* @public
* @example
* const claim = Claim('https://alice.tld', '123');
* const pers = Persona('Alice', 'About Alice', [claim]);
*/
class Persona {
/**
* @param {string} name
* @param {import('./claim.js').Claim[]} claims
*/
constructor (name, claims) {
/**
* Identifier of the persona
* @type {string | null}
* @public
*/
this.identifier = null;
/**
* Name to be displayed on the profile page
* @type {string}
* @public
*/
this.name = name;
/**
* Email address of the persona
* @type {string | null}
* @public
*/
this.email = null;
/**
* Description to be displayed on the profile page
* @type {string | null}
* @public
*/
this.description = null;
/**
* URL to an avatar image
* @type {string | null}
* @public
*/
this.avatarUrl = null;
/**
* List of identity claims
* @type {import('./claim.js').Claim[]}
* @public
*/
this.claims = claims;
/**
* Has the persona been revoked
* @type {boolean}
* @public
*/
this.isRevoked = false;
}
/**
* @function
* @param {object} personaObject
* @param {number} profileVersion
* @returns {Persona | Error}
* @example
* doip.Persona.fromJSON(JSON.stringify(persona), 2);
*/
static fromJSON (personaObject, profileVersion) {
/** @type {Persona} */
let persona;
let result;
if (typeof personaObject === 'object' && profileVersion) {
switch (profileVersion) {
case 2:
result = importJsonPersonaVersion2(personaObject);
if (result instanceof Error) {
throw result
}
persona = result;
break
default:
throw new Error('Invalid persona version')
}
}
return persona
}
/**
* @function
* @param {string} identifier
*/
setIdentifier (identifier) {
this.identifier = identifier;
}
/**
* @function
* @param {string} description
*/
setDescription (description) {
this.description = description;
}
/**
* @function
* @param {string} email
*/
setEmailAddress (email) {
this.email = email;
}
/**
* @function
* @param {string} avatarUrl
*/
setAvatarUrl (avatarUrl) {
this.avatarUrl = avatarUrl;
}
/**
* @function
* @param {import('./claim.js').Claim} claim
*/
addClaim (claim) {
this.claims.push(claim);
}
/**
* @function
*/
revoke () {
this.isRevoked = true;
}
/**
* Get a JSON representation of the Profile object
* @function
* @returns {object}
*/
toJSON () {
return {
identifier: this.identifier,
name: this.name,
email: this.email,
description: this.description,
avatarUrl: this.avatarUrl,
isRevoked: this.isRevoked,
claims: this.claims.map(x => x.toJSON())
}
}
}
/**
* @param {object} personaObject
* @returns {Persona | Error}
*/
function importJsonPersonaVersion2 (personaObject) {
const claims = personaObject.claims.map(x => Claim.fromJSON(x));
const persona = new Persona(personaObject.name, claims);
persona.identifier = personaObject.identifier;
persona.email = personaObject.email;
persona.description = personaObject.description;
persona.avatarUrl = personaObject.avatarUrl;
persona.isRevoked = personaObject.isRevoked;
return persona
}
/*
Copyright 2023 Yarmo Mackenbach
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.
*/
/**
* A profile of personas with identity claims
* @function
* @param {Array<import('./persona.js').Persona>} personas
* @public
* @example
* const claim = Claim('https://alice.tld', '123');
* const pers = Persona('Alice', 'About Alice', [claim]);
* const profile = Profile([pers]);
*/
class Profile {
/**
* Create a new profile
* @function
* @param {import('./enums.js').ProfileType} profileType
* @param {string} identifier
* @param {Array<import('./persona.js').Persona>} personas
* @public
*/
constructor (profileType, identifier, personas) {
/**
* Profile version
* @type {number}
* @public
*/
this.profileVersion = 2;
/**
* Profile version
* @type {import('./enums.js').ProfileType}
* @public
*/
this.profileType = profileType;
/**
* Identifier of the profile (fingerprint, email address, uri...)
* @type {string}
* @public
*/
this.identifier = identifier;
/**
* List of personas
* @type {Array<import('./persona.js').Persona>}
* @public
*/
this.personas = personas || [];
/**
* Index of primary persona (to be displayed first or prominently)
* @type {number}
* @public
*/
this.primaryPersonaIndex = personas.length > 0 ? 0 : -1;
/**
* The cryptographic key associated with the profile
* @property {object}
* @public
*/
this.publicKey = {
/**
* The type of cryptographic key
* @type {PublicKeyType}
* @public
*/
keyType: PublicKeyType.NONE,
/**
* The fingerprint of the cryptographic key
* @type {string | null}
* @public
*/
fingerprint: null,
/**
* The encoding of the cryptographic key
* @type {PublicKeyEncoding}
* @public
*/
encoding: PublicKeyEncoding.NONE,
/**
* The encoded cryptographic key
* @type {string | null}
* @public
*/
encodedKey: null,
/**
* The raw cryptographic key as object (to be removed during toJSON())
* @type {import('openpgp').PublicKey | import('jose').JWK | null}
* @public
*/
key: null,
/**
* Details on how to fetch the public key
* @property {object}
* @public
*/
fetch: {
/**
* The method to fetch the key
* @type {PublicKeyFetchMethod}
* @public
*/
method: PublicKeyFetchMethod.NONE,
/**
* The query to fetch the key
* @type {string | null}
* @public
*/
query: null,
/**
* The URL the method eventually resolved to
* @type {string | null}
* @public
*/
resolvedUrl: null
}
};
/**
* List of verifier URLs
* @type {{name: string, url: string}[]}
* @public
*/
this.verifiers = [];
}
/**
* @function
* @param {object} profileObject
* @returns {Profile | Error}
* @example
* doip.Profile.fromJSON(JSON.stringify(profile));
*/
static fromJSON (profileObject) {
/** @type {Profile} */
let profile;
let result;
if (typeof profileObject === 'object' && 'profileVersion' in profileObject) {
switch (profileObject.profileVersion) {
case 2:
result = importJsonProfileVersion2(profileObject);
if (result instanceof Error) {
throw result
}
profile = result;
break
default:
throw new Error('Invalid profile version')
}
}
return profile
}
/**
* @function
* @param {string} name
* @param {string} url
*/
addVerifier (name, url) {
this.verifiers.push({ name, url });
}
/**
* Get a JSON representation of the Profile object
* @function
* @returns {object}
*/
toJSON () {
return {
profileVersion: this.profileVersion,
profileType: this.profileType,
identifier: this.identifier,
personas: this.personas.map(x => x.toJSON()),
primaryPersonaIndex: this.primaryPersonaIndex,
publicKey: {
keyType: this.publicKey.keyType,
fingerprint: this.publicKey.fingerprint,
encoding: this.publicKey.encoding,
encodedKey: this.publicKey.encodedKey,
fetch: {
method: this.publicKey.fetch.method,
query: this.publicKey.fetch.query,
resolvedUrl: this.publicKey.fetch.resolvedUrl
}
},
verifiers: this.verifiers
}
}
}
/**
* @param {object} profileObject
* @returns {Profile | Error}
*/
function importJsonProfileVersion2 (profileObject) {
if (!('profileVersion' in profileObject && profileObject.profileVersion === 2)) {
return new Error('Invalid profile')
}
const personas = profileObject.personas.map(x => Persona.fromJSON(x, 2));
const profile = new Profile(profileObject.profileType, profileObject.identifier, personas);
profile.primaryPersonaIndex = profileObject.primaryPersonaIndex;
profile.publicKey = profileObject.publicKey;
profile.verifiers = profileObject.verifiers;
return profile
}
var axios$3 = {exports: {}};
var bind$2 = function bind(fn, thisArg) {

File diff suppressed because one or more lines are too long

View file

@ -2728,7 +2728,7 @@ var doipFetchers = (function (exports) {
* doip.js library version
* @constant {string}
*/
const version = '1.0.4';
const version = '1.1.0';
/*
Copyright 2022 Yarmo Mackenbach

File diff suppressed because one or more lines are too long

View file

@ -2698,7 +2698,7 @@ var doipFetchers = (function (exports) {
* doip.js library version
* @constant {string}
*/
const version = '1.0.4';
const version = '1.1.0';
/*
Copyright 2022 Yarmo Mackenbach

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "doipjs",
"version": "1.0.4",
"version": "1.1.0",
"description": "Decentralized Online Identity Proofs library in Node.js",
"type": "module",
"main": "./src/index.js",

View file

@ -22,4 +22,4 @@ limitations under the License.
* doip.js library version
* @constant {string}
*/
export const version = '1.0.4'
export const version = '1.1.0'