@digitaltg/vc-signer
v1.0.0
Published
Une version offline de signature de Verifiable Credential
Readme
VC Signer
Une version offline de signature de Verifiable Credential
Utilisation
On installe la librairie avec la commande suivante
npm install @digitaltg/vc-signer/* eslint-disable @typescript-eslint/no-require-imports */
const { VcSign } = require('../dist/index');
const { PRIVATE_KEY } = require('./data/privateKey');
const { SCHEMA_DEFINITION } = require('./data/schema');
const { TEMPLATE } = require('./data/template');
(async () => {
VcSign.sign(
'FRTRtrSchemaV1',
SCHEMA_DEFINITION,
{
it: '1234',
},
PRIVATE_KEY,
{
TEMPLATE_JSON: TEMPLATE,
TYPE: 'sample',
VERSION: '1',
DOMAIN: 'gouv.tg',
},
)
.then((res) => {
console.log('Result', res);
})
.catch((error) => {
console.error('Error', error);
});
})();Les informations comme la clé, le template et le schema définition ont le format suivant:
private key{
'@context': [
'https://www.w3.org/ns/did/v1',
'https://w3id.org/security/suites/ed25519-2020/v1',
],
id: 'did:web:vcs.local:1#eddsa_key',
controller: 'did:web:vcs.local:1',
type: 'Ed25519VerificationKey2020',
privateKeyMultibase:
'z3PfAbmXssjhWuedrhkuJtQFtRkGxANdBubwG6NPeKbvDYBzhaj8mCZ7uVSs3PoaWZBYmf4djzeh2f5jip4PXiQp2',
publicKeyMultibase: 'z2NhvcRS8aSHMXVb34nNyvxTZFbnwu4g23JPk1o7NvLan',
},Template{
'sample:1': {
columns: [
{
path: 'issuanceDate',
encoder: 'isodatetime-epoch-base32',
},
{
path: 'issuer',
encoder: 'string',
prefix: ['did:web:digital.gouv.tg'],
},
{
path: 'id',
encoder: 'string',
},
{
path: 'proof.verificationMethod',
encoder: 'string',
prefix: ['did:web:172.17.0.1'],
},
{
path: 'proof.proofValue',
encoder: 'multibase-base36',
},
{
path: 'proof.created',
encoder: 'isodatetime-epoch-base32',
},
{
path: 'credentialSubject.objet',
encoder: 'string',
},
{
path: 'credentialSubject.type',
encoder: 'string',
},
{
path: 'credentialSubject.it',
encoder: 'string',
},
{
path: 'credentialSubject.cat',
encoder: 'string',
},
{
path: 'credentialSubject.exp',
encoder: 'string',
},
{
path: 'credentialSubject.rat',
encoder: 'string',
},
],
template: {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://w3id.org/security/suites/ed25519-2020/v1',
'http://vcs.local/1/contexts/FRTRtrSchemaV1.jsonld',
],
type: ['VerifiableCredential'],
credentialSubject: {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://w3id.org/security/suites/ed25519-2020/v1',
'http://vcs.local/1/contexts/FRTRtrSchemaV1.jsonld',
],
type: 'FRTRtrSchemaV1',
},
proof: {
type: 'Ed25519Signature2020',
proofPurpose: 'assertionMethod',
},
},
},
};Schema Definition{
$schema: 'http://json-schema.org/draft-07/schema',
type: 'object',
properties: {
FRTRtrSchemaV1: {
$ref: '#/definitions/FRTRtrSchemaV1',
},
},
required: ['FRTRtrSchemaV1'],
title: 'FRTRtrSchemaV1',
description: 'Description',
definitions: {
FRTRtrSchemaV1: {
$id: '#/properties/FRTRtrSchemaV1',
title: 'FRTRtrSchemaV1',
description: '',
type: 'object',
properties: {
cat: {
type: 'string',
},
exp: {
type: 'string',
},
rat: {
type: 'string',
},
it: {
type: 'string',
},
},
required: ['it', 'cat', 'exp', 'rat'],
},
},
_osConfig: {
enableLogin: false,
indexFields: ['it'],
uniqueIndexFields: ['it'],
roles: ['schema', 'rtr'],
inviteRoles: ['admin', 'anonymous'],
ownershipAttributes: [],
attestationAttributes: ['it', 'cat', 'exp', 'rat'],
attestationPolicies: [
{
name: 'FRTRtrSchemaV1Attestation',
attestationProperties: {
cat: '$.cat',
exp: '$.exp',
rat: '$.rat',
it: '$.it',
},
type: 'MANUAL',
conditions: 'true',
attestorPlugin:
'did:internal:ClaimPluginActor?entity=FRTAttestatorSchemaV1,admin',
},
],
credentialTemplate: {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'http://vcs.local/1/contexts/FRTRtrSchemaV1.jsonld',
],
type: ['VerifiableCredential'],
issuanceDate: '2023-01-01T00:00:00Z',
credentialSubject: {
type: 'FRTRtrSchemaV1',
it: '{{it}}',
cat: '{{cat}}',
exp: '{{exp}}',
rat: '{{rat}}',
},
issuer: 'did:web:digital.gouv.tg',
},
},
}Ces trois données peuvent s'obtenir facilement si l'on dispose de l'application de Gouv Registry.
Développement
Pour tester le build de dist et de bundle
npm run tests-dry:distnpm run tests-dry:bundleBugs
Exécution de tests automatiques
Avec l'exécution du test, on a le retrou suivant:
TypeError: Cannot read properties of undefined (reading 'constants')
at Object.<anonymous> (node_modules/@digitalbazaar/ed25519-signature-2020/lib/Ed25519Signature2020.js:14:44)
at Object.<anonymous> (/home/xampy/Project/gouvregistry/vc-signer-npm/node_modules/@digitalbazaar/ed25519-signature-2020/lib/main.js:1)A revoir sutour les transform ignore comme démarrage de piste
