Open-Attestation / open-attestation

Meta framework for providing digital provenance and integrity to documents.
https://openattestation.com
Apache License 2.0
54 stars 18 forks source link

Feat:document builder #283

Closed phanshiyu closed 5 months ago

phanshiyu commented 5 months ago

in an attempt to simplify the issuance process via a builder interface:

before

const wrapped = wrapDocument({
  "@context": [
    "https://www.w3.org/ns/credentials/v2",
    "https://schemata.openattestation.com/com/openattestation/4.0/alpha-context.json",
  ],
  type: ["VerifiableCredential", "OpenAttestationCredential"],
  validFrom: "2021-03-08T12:00:00+08:00",
  name: "Republic of Singapore Driving Licence",
  issuer: {
    id: "https://example.openattestation.com",
    type: "OpenAttestationIssuer",
    name: "Government Technology Agency of Singapore (GovTech)",
    identityProof: { identityProofType: "DNS-DID", identifier: "example.openattestation.com" },
  },
  renderMethod: [
    {
      id: "https://demo-renderer.opencerts.io",
      type: "OpenAttestationEmbeddedRenderer",
      templateName: "GOVTECH_DEMO",
    },
  ],
  credentialSubject: {
    id: "urn:uuid:a013fb9d-bb03-4056-b696-05575eceaf42",
    type: ["DriversLicense"],
    name: "John Doe",
    licenses: [
      {
        class: "3",
        description: "Motor cars with unladen weight <= 3000kg",
        effectiveDate: "2013-05-16T00:00:00+08:00",
      },
      {
        class: "3A",
        description: "Motor cars with unladen weight <= 3000kg",
        effectiveDate: "2013-05-16T00:00:00+08:00",
      },
    ],
  },
});

signDocument(wrapped, "Secp256k1VerificationKey2018", SIGNER);

after (something like that)

single DID TXT issuance

new DocumentBuilder({
  name: "Republic of Singapore Driving Licence",
  content: {
    id: "urn:uuid:a013fb9d-bb03-4056-b696-05575eceaf42",
    type: ["DriversLicense"],
    name: "John Doe",
    licenses: [
      {
        class: "3",
        description: "Motor cars with unladen weight <= 3000kg",
        effectiveDate: "2013-05-16T00:00:00+08:00",
      },
      {
        class: "3A",
        description: "Motor cars with unladen weight <= 3000kg",
        effectiveDate: "2013-05-16T00:00:00+08:00",
      },
    ],
  },
})
  .embeddedRenderer({
    templateName: "GOVTECH_DEMO",
    rendererUrl: "https://demo-renderer.opencerts.io",
  })
  .dnsTxtIssuance({
    identityProofDomain: "example.openattestation.com",
    issuerName: "Government Technology Agency of Singapore (GovTech)",
    issuerId: "urn:uuid:a013fb9d-bb03-4056-b696-05575eceaf42",
  })
  .wrapAndSign({
    signer: SAMPLE_SIGNING_KEYS,
  })
  .then((signed) => {
    console.log(signed.credentialSubject);
  });

batch DID TXT issuance

new DocumentBuilder([
  {
    name: "Republic of Singapore Driving Licence",
    content: {
      id: "urn:uuid:a013fb9d-bb03-4056-b696-05575eceaf42",
      type: ["DriversLicense"],
      name: "John Doe",
      licenses: [
        {
          class: "3",
          description: "Motor cars with unladen weight <= 3000kg",
          effectiveDate: "2013-05-16T00:00:00+08:00",
        },
        {
          class: "3A",
          description: "Motor cars with unladen weight <= 3000kg",
          effectiveDate: "2013-05-16T00:00:00+08:00",
        },
      ],
    },
  },
  {
    name: "Republic of Singapore Driving Licence",
    content: {
      id: "urn:uuid:12344-1234-1234-1234-1234",
      type: ["SpaceShipLicense"],
      name: "Jane Foster",
      licenses: [
        {
          class: "300",
          description: "Motor spaceships with unladen weight <= 3000tone",
          effectiveDate: "2100-05-16T00:00:00+08:00",
        },
      ],
    },
  },
])
  .embeddedRenderer({
    templateName: "GOVTECH_DEMO",
    rendererUrl: "https://demo-renderer.opencerts.io",
  })
  .dnsTxtIssuance({
    identityProofDomain: "example.openattestation.com",
    issuerName: "Government Technology Agency of Singapore (GovTech)",
    issuerId: "urn:uuid:a013fb9d-bb03-4056-b696-05575eceaf42",
  })
  .wrapAndSign({
    signer: SAMPLE_SIGNING_KEYS,
  })
  .then((signed) => {
    console.log(signed);
  });
github-actions[bot] commented 5 months ago

:tada: This PR is included in version 6.10.0-alpha.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: