openwallet-foundation/credo-ts

X509: Cannot initialize GeneralNames. Incorrect incoming arguments

Closed this issue · 2 comments

Trying to use createSelfSignedCertificate but getting type errors (commented in code). If I ignore the type errors, I get this error:

/Users/jr/Projects/typescript-project/node_modules/@peculiar/x509/build/x509.cjs.js:1034
            throw new Error("Cannot initialize GeneralNames. Incorrect incoming arguments");
                  ^
Error: Cannot initialize GeneralNames. Incorrect incoming arguments
    at new GeneralNames (/Users/jr/Projects/typescript-project/node_modules/@peculiar/x509/build/x509.cjs.js:1034:19)
    at new SubjectAlternativeNameExtension (/Users/jr/Projects/typescript-project/node_modules/@peculiar/x509/build/x509.cjs.js:1763:70)
    at /Users/jr/Projects/typescript-project/node_modules/@credo-ts/core/src/modules/x509/X509Certificate.ts:111:52
    at Array.map (<anonymous>)
    at Function.createSelfSigned (/Users/jr/Projects/typescript-project/node_modules/@credo-ts/core/src/modules/x509/X509Certificate.ts:111:33)
    at Function.createSelfSignedCertificate (/Users/jr/Projects/typescript-project/node_modules/@credo-ts/core/src/modules/x509/X509Service.ts:119:47)
    at X509Api.createSelfSignedCertificate (/Users/jr/Projects/typescript-project/node_modules/@credo-ts/core/src/modules/x509/X509Api.ts:43:30)
    at /Users/jr/Projects/typescript-project/bug.ts:40:33

Code:

import { Agent, InitConfig, KeyBackend, KeyType } from "@credo-ts/core";
import { agentDependencies } from "@credo-ts/node";
import { ariesAskar } from "@hyperledger/aries-askar-nodejs";
import { AskarModule } from "@credo-ts/askar";
import { Router } from "express";
import { OpenId4VcIssuerModule } from "@credo-ts/openid4vc";

export const openId4VciRouter = Router();

(async () => {
  const config = {
    label: "name",
    walletConfig: { id: "name", key: "name" },
  } satisfies InitConfig;
  const agent = new Agent({
    config,
    dependencies: agentDependencies,
    modules: {
      askar: new AskarModule({ ariesAskar }),
      openId4VcIssuer: new OpenId4VcIssuerModule({
        baseUrl: "http://localhost:2000/oid4vci",
        router: openId4VciRouter,
        endpoints: {
          credential: {
            // @ts-expect-error
            credentialRequestToCredentialMapper: (...args) => null,
          },
        },
      }),
    },
  });

  await agent.initialize();

  // not sure how to get he default agent key so creating another one
  const myKey = await agent.wallet.createKey({
    keyType: KeyType.Ed25519,
  });

  const cert = await agent.x509.createSelfSignedCertificate({
    key: myKey,
    extensions: [
      // @ts-expect-error - Object literal may only specify known properties, and 'type' does not exist in type '{ type: "url" | "dns"; value: string; }[]'.ts(2353)
      { type: "url", value: "animo.id" },
      // @ts-expect-error - Object literal may only specify known properties, and 'type' does not exist in type '{ type: "url" | "dns"; value: string; }[]'.ts(2353)
      { type: "dns", value: "paradym.id" },
    ],
  });

  console.log({ cert, str: cert.toString("base64") });
})();

Packages:

    "@credo-ts/askar": "^0.5.9",
    "@credo-ts/core": "^0.5.9",
    "@credo-ts/node": "^0.5.9",
    "@credo-ts/openid4vc": "^0.5.9",
    "@hyperledger/aries-askar-nodejs": "0.2.3",

Hi!

Calling the agent.x509.createSelfSignedCertificate is being called with the wrong arguments.

  const cert = await agent.x509.createSelfSignedCertificate({
    key: myKey,
    extensions: [
-     // @ts-expect-error - Object literal may only specify known properties, and 'type' does not exist in type '{ type: "url" | "dns"; value: string; }[]'.ts(2353)
-     { type: "url", value: "animo.id" },
+     [{ type: "url", value: "animo.id" }],
-     // @ts-expect-error - Object literal may only specify known properties, and 'type' does not exist in type '{ type: "url" | "dns"; value: string; }[]'.ts(2353)
-     { type: "dns", value: "paradym.id" },
+     [{ type: "dns", value: "paradym.id" }],
    ],
  });

Every extension can have mulitple entries and you can have multiple extensions, so it has to be a list of lists.

Awesome, thanks!