@coordination-network/credential 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,6 @@
1
1
  # @coordination-network/credential
2
2
 
3
- The credential SDK for the coordination network: issuing, verifying and presenting the delegated user approval credential, in both of the forms the network uses.
4
-
5
- - **SD-JWT VC**, for selective disclosure. The holder chooses which claims to reveal, and a key-binding JWT proves the presentation came from the device the credential was bound to.
6
- - **ZK credential**, for unlinkable presentation. The holder proves in zero knowledge that an approved issuer signed a credential that has not been revoked, without revealing the credential, the issuer or themselves.
3
+ The zero-knowledge credential SDK for the Coordination Network. It issues signed credentials and builds or verifies presentations that prove approval and non-revocation without revealing the credential, its holder, or its issuer.
7
4
 
8
5
  ## Install
9
6
 
@@ -11,57 +8,31 @@ The credential SDK for the coordination network: issuing, verifying and presenti
11
8
  yarn add @coordination-network/credential
12
9
  ```
13
10
 
14
- The zero-knowledge paths load [`@noir-lang/noir_js`](https://noir-lang.org) and [`@aztec/bb.js`](https://github.com/AztecProtocol/aztec-packages) lazily, so an application that only issues or verifies SD-JWT credentials never pulls the proving stack into its startup path.
15
-
16
- ## Usage
17
-
18
- ### Issuing
19
-
20
- ```ts
21
- import { issueSdJwtCredential } from "@coordination-network/credential"
22
-
23
- const token = await issueSdJwtCredential(params, signer, approvalResolver)
24
- ```
25
-
26
- ### Verifying
11
+ ## Supported credential flow
27
12
 
28
- ```ts
29
- import { verifySdJwtCredential } from "@coordination-network/credential"
13
+ - `issueZkCredential` validates the holder bindings and signs the credential commitments.
14
+ - `buildZkPresentationInputs` constructs private circuit inputs on the holder device.
15
+ - `ZkCredentialProofSystem` creates and verifies the zero-knowledge presentation.
16
+ - `ApprovedIssuerSet` and the revocation helpers provide the membership witnesses used by the circuit.
30
17
 
31
- const result = await verifySdJwtCredential(token, resolver)
32
- ```
18
+ The previous SD-JWT prototype is intentionally not part of this package. It exposed stable subject, issuer, device-key, and revocation identifiers and did not provide the privacy properties of the supported ZK flow.
33
19
 
34
- ### Presenting
20
+ ## Verifying a presentation
35
21
 
36
22
  ```ts
37
- import { presentSdJwtCredential, verifySdJwtPresentation } from "@coordination-network/credential"
38
-
39
- const presentation = await presentSdJwtCredential(token, deviceSigner, {
40
- audience: verifierId,
41
- nonce,
42
- disclose: ["programme", "country"]
43
- })
23
+ import { verifyZkPresentationProof } from "@coordination-network/credential"
44
24
 
45
- const result = await verifySdJwtPresentation(presentation, resolver, { audience: verifierId, nonce })
25
+ const result = await verifyZkPresentationProof(circuit, proof, expected)
46
26
  ```
47
27
 
48
- ### Revocation
28
+ On success the result carries `approvedIssuerRoot` and `revocationRoot`, the proof's public outputs. The function does not check them, so check them against the registries before accepting the presentation: the issuer root against the approved-issuer set, and the revocation root with the revocation registry's `isValidRoot`.
49
29
 
50
- ```ts
51
- import {
52
- generateRevocationSecret,
53
- deriveRevocationCommitment,
54
- buildStatusClaim
55
- } from "@coordination-network/credential"
56
-
57
- const secret = generateRevocationSecret()
58
- const commitment = deriveRevocationCommitment(secret)
59
- ```
30
+ ## Revocation
60
31
 
61
- The holder generates the secret and shows the issuer the commitment, with `signCommitmentOwnership` / `verifyCommitmentOwnership` proving they hold the preimage. The issuer embeds the commitment in the credential's status claim. Revoking later means inserting that commitment into [`@coordination-network/revocation-registry`](../revocation-registry), and proving a credential is still valid means proving the commitment is absent from it. |
32
+ The holder generates a secret with `generateRevocationSecret` and sends only its commitment to the issuer. `signCommitmentOwnership` and `verifyCommitmentOwnership` prove control of the commitment during issuance. A presentation later proves that commitment is absent from the revocation registry without disclosing it.
62
33
 
63
34
  ## Notes
64
35
 
65
- - The signer interfaces are structural, so keys can live in a KMS, a hardware wallet or a device keystore without this package knowing.
66
- - `ApprovalResolver` and `IssuerSet` are the two seams onto network membership. [`@coordination-network/issuer-set`](../issuer-set) provides an implementation of the latter.
67
- - This package ships a CommonJS build. Both `import` and `require` work.
36
+ - Device signer interfaces are structural, so keys can remain in a hardware-backed keystore.
37
+ - Noir and Barretenberg are loaded lazily by the proof-system helpers.
38
+ - This package ships a CommonJS build; both `import` and `require` are supported.
package/dist/crypto.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { bytesToBase64url } from "@coordination-network/identity";
2
2
  import { Jwk } from "./types";
3
- import { DeviceSigner, Signer } from "./signer";
3
+ import { DeviceSigner } from "./signer";
4
4
  export { bytesToBase64url };
5
5
  /**
6
6
  * Padding is optional under RFC 4648 §5 and some clients send it anyway (Python's
@@ -25,23 +25,15 @@ export declare function jwkThumbprint(jwk: Jwk): Uint8Array;
25
25
  * and JWS does not require it.
26
26
  */
27
27
  export declare function verifyP256(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean;
28
- /** Bridges a Signer to the @sd-jwt signer callback (base64url over utf8 input). */
29
- export declare function createSdJwtSigner(signer: Signer): (data: string) => Promise<string>;
30
- /** Builds the @sd-jwt verifier callback from a resolved issuer JWK. */
31
- export declare function createSdJwtVerifier(jwk: Jwk): (data: string, signature: string) => boolean;
32
- /** The sha-256 hasher the @sd-jwt config takes. */
33
- export declare function sdJwtHasher(data: string | ArrayBuffer): Uint8Array;
34
- /** Hex salts for disclosure digests. */
35
- export declare function sdJwtSaltGenerator(length: number): string;
36
28
  /** RFC 4122 v4 UUID from CSPRNG bytes — node:crypto is unavailable under React Native. */
37
29
  export declare function randomUuid(): string;
38
30
  /**
39
31
  * Software P-256 signer. The issuer demo and every test use it; production
40
32
  * issuers replace it with a KMS-backed Signer, apps with a secure-element
41
33
  * DeviceSigner. Signs in message mode with low-s, raw 64-byte output —
42
- * exactly the Signer contract.
34
+ * exactly the DeviceSigner contract.
43
35
  */
44
- export declare class LocalP256Signer implements Signer, DeviceSigner {
36
+ export declare class LocalP256Signer implements DeviceSigner {
45
37
  private readonly privateKey;
46
38
  constructor(privateKey: Uint8Array);
47
39
  static generate(): LocalP256Signer;
package/dist/crypto.js CHANGED
@@ -7,18 +7,12 @@ exports.compressedPointToJwk = compressedPointToJwk;
7
7
  exports.jwkToCompressedPoint = jwkToCompressedPoint;
8
8
  exports.jwkThumbprint = jwkThumbprint;
9
9
  exports.verifyP256 = verifyP256;
10
- exports.createSdJwtSigner = createSdJwtSigner;
11
- exports.createSdJwtVerifier = createSdJwtVerifier;
12
- exports.sdJwtHasher = sdJwtHasher;
13
- exports.sdJwtSaltGenerator = sdJwtSaltGenerator;
14
10
  exports.randomUuid = randomUuid;
15
11
  const nist_js_1 = require("@noble/curves/nist.js");
16
12
  const sha2_1 = require("@noble/hashes/sha2");
17
13
  const utils_1 = require("@noble/hashes/utils");
18
14
  const identity_1 = require("@coordination-network/identity");
19
15
  Object.defineProperty(exports, "bytesToBase64url", { enumerable: true, get: function () { return identity_1.bytesToBase64url; } });
20
- /** Bridges the KMS-shaped Signer interface, the noble primitives, and the callback shapes @sd-jwt expects. */
21
- const utf8 = (data) => new TextEncoder().encode(data);
22
16
  /**
23
17
  * Padding is optional under RFC 4648 §5 and some clients send it anyway (Python's
24
18
  * urlsafe_b64encode, Java's URL encoder), so JWK coordinates are stripped before the strict decode
@@ -78,30 +72,6 @@ function verifyP256(message, signature, publicKey) {
78
72
  return false;
79
73
  }
80
74
  }
81
- /** Bridges a Signer to the @sd-jwt signer callback (base64url over utf8 input). */
82
- function createSdJwtSigner(signer) {
83
- return async (data) => (0, identity_1.bytesToBase64url)(await signer.sign(utf8(data)));
84
- }
85
- /** Builds the @sd-jwt verifier callback from a resolved issuer JWK. */
86
- function createSdJwtVerifier(jwk) {
87
- const publicKey = jwkToPublicKeyBytes(jwk);
88
- return (data, signature) => {
89
- try {
90
- return verifyP256(utf8(data), base64urlToBytes(signature), publicKey);
91
- }
92
- catch {
93
- return false;
94
- }
95
- };
96
- }
97
- /** The sha-256 hasher the @sd-jwt config takes. */
98
- function sdJwtHasher(data) {
99
- return (0, sha2_1.sha256)(typeof data === "string" ? data : new Uint8Array(data));
100
- }
101
- /** Hex salts for disclosure digests. */
102
- function sdJwtSaltGenerator(length) {
103
- return (0, utils_1.bytesToHex)((0, utils_1.randomBytes)(length));
104
- }
105
75
  /** RFC 4122 v4 UUID from CSPRNG bytes — node:crypto is unavailable under React Native. */
106
76
  function randomUuid() {
107
77
  const bytes = (0, utils_1.randomBytes)(16);
@@ -114,7 +84,7 @@ function randomUuid() {
114
84
  * Software P-256 signer. The issuer demo and every test use it; production
115
85
  * issuers replace it with a KMS-backed Signer, apps with a secure-element
116
86
  * DeviceSigner. Signs in message mode with low-s, raw 64-byte output —
117
- * exactly the Signer contract.
87
+ * exactly the DeviceSigner contract.
118
88
  */
119
89
  class LocalP256Signer {
120
90
  constructor(privateKey) {
package/dist/index.d.ts CHANGED
@@ -11,9 +11,4 @@ export * from "./zk-proof";
11
11
  export * from "./resolver";
12
12
  export * from "./registry-client";
13
13
  export * from "./crypto";
14
- export * from "./decode";
15
- export * from "./profile";
16
- export * from "./issue";
17
- export * from "./verify";
18
- export * from "./present";
19
14
  export * from "./revocation";
package/dist/index.js CHANGED
@@ -27,9 +27,4 @@ __exportStar(require("./zk-proof"), exports);
27
27
  __exportStar(require("./resolver"), exports);
28
28
  __exportStar(require("./registry-client"), exports);
29
29
  __exportStar(require("./crypto"), exports);
30
- __exportStar(require("./decode"), exports);
31
- __exportStar(require("./profile"), exports);
32
- __exportStar(require("./issue"), exports);
33
- __exportStar(require("./verify"), exports);
34
- __exportStar(require("./present"), exports);
35
30
  __exportStar(require("./revocation"), exports);
@@ -1,4 +1,8 @@
1
1
  import { CredentialSigner } from "./credential-signer";
2
2
  import { ApprovalResolver } from "./resolver";
3
- import { ZkCredential, ZkCredentialIssueParams } from "./types";
3
+ import { ZkCredential, ZkCredentialBody, ZkCredentialIssueParams } from "./types";
4
+ /** Validates an issuance request without signing it. */
5
+ export declare function validateZkCredentialIssue(params: ZkCredentialIssueParams, approval: ApprovalResolver): Promise<ZkCredentialBody>;
6
+ /** Signs a request that has already passed {@link validateZkCredentialIssue}. */
7
+ export declare function signValidatedZkCredential(body: ZkCredentialBody, signer: CredentialSigner): Promise<ZkCredential>;
4
8
  export declare function issueZkCredential(params: ZkCredentialIssueParams, signer: CredentialSigner, approval: ApprovalResolver): Promise<ZkCredential>;
@@ -1,20 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateZkCredentialIssue = validateZkCredentialIssue;
4
+ exports.signValidatedZkCredential = signValidatedZkCredential;
3
5
  exports.issueZkCredential = issueZkCredential;
4
6
  const identity_1 = require("@coordination-network/identity");
7
+ const issuer_set_1 = require("@coordination-network/issuer-set");
5
8
  const utils_1 = require("@noble/hashes/utils");
6
9
  const identity_2 = require("@semaphore-protocol/identity");
7
10
  const credential_message_1 = require("./credential-message");
8
11
  const crypto_1 = require("./crypto");
9
12
  const errors_1 = require("./errors");
10
13
  const revocation_1 = require("./revocation");
11
- async function issueZkCredential(params, signer, approval) {
14
+ /** Validates an issuance request without signing it. */
15
+ async function validateZkCredentialIssue(params, approval) {
12
16
  if (!(await approval.isApprovedNetworkMember(params.issuerNetworkId))) {
13
17
  throw new errors_1.IssuanceError("ISSUER_NOT_APPROVED", `issuer ${params.issuerNetworkId} is not an approved network member`);
14
18
  }
15
19
  if (!(params.validFrom < params.validUntil)) {
16
20
  throw new errors_1.IssuanceError("INVALID_PARAMS", "validFrom must be before validUntil");
17
21
  }
22
+ if (!(0, issuer_set_1.inPrimeOrderSubgroup)(params.identityPublicKey)) {
23
+ throw new errors_1.IssuanceError("INVALID_PARAMS", "identity public key is not in the prime-order subgroup");
24
+ }
18
25
  const holderKeyCommitment = identity_2.Identity.generateCommitment(params.identityPublicKey);
19
26
  const holderKeyCommitmentBytes = (0, utils_1.hexToBytes)(holderKeyCommitment.toString(16).padStart(64, "0"));
20
27
  let binding;
@@ -49,7 +56,7 @@ async function issueZkCredential(params, signer, approval) {
49
56
  if (!ownershipOk) {
50
57
  throw new errors_1.IssuanceError("COMMITMENT_OWNERSHIP_INVALID", "revocation commitment ownership proof failed");
51
58
  }
52
- const body = {
59
+ return {
53
60
  programmeHash: (0, credential_message_1.programmeHash)(params.approvalScope.programme),
54
61
  countryCode: (0, credential_message_1.countryCode)(params.approvalScope.country),
55
62
  notBefore: params.validFrom,
@@ -58,9 +65,15 @@ async function issueZkCredential(params, signer, approval) {
58
65
  holderKeyCommitment,
59
66
  revocationCommitment: params.revocation.commitment
60
67
  };
68
+ }
69
+ /** Signs a request that has already passed {@link validateZkCredentialIssue}. */
70
+ async function signValidatedZkCredential(body, signer) {
61
71
  return {
62
72
  body,
63
73
  issuerPublicKey: await signer.getPublicKey(),
64
74
  signature: await signer.sign((0, credential_message_1.zkCredentialCommitment)(body))
65
75
  };
66
76
  }
77
+ async function issueZkCredential(params, signer, approval) {
78
+ return signValidatedZkCredential(await validateZkCredentialIssue(params, approval), signer);
79
+ }
@@ -1,4 +1,4 @@
1
- import { EddsaPublicKey, EddsaSignature, StatusClaim } from "./types";
1
+ import { EddsaPublicKey, EddsaSignature } from "./types";
2
2
  /** Generates a fresh 32-byte revocation secret r. Device-side only. */
3
3
  export declare function generateRevocationSecret(): Uint8Array;
4
4
  /** commitment = new Identity(r).commitment (Semaphore V4). */
@@ -12,8 +12,10 @@ export declare function signCommitmentOwnership(r: Uint8Array, nonce: Uint8Array
12
12
  signature: EddsaSignature;
13
13
  };
14
14
  /**
15
- * Issuer-side check: verifies the EdDSA signature over the nonce, recomputes
16
- * the commitment from the public key, and compares it to the claimed one.
15
+ * Issuer-side check: requires a prime-order public key, verifies the EdDSA
16
+ * signature over the nonce, recomputes the commitment from the public key, and
17
+ * compares it to the claimed one. A low-order key is refused because its
18
+ * signatures need no secret.
17
19
  */
18
20
  export declare function verifyCommitmentOwnership(params: {
19
21
  commitment: bigint;
@@ -21,5 +23,3 @@ export declare function verifyCommitmentOwnership(params: {
21
23
  signature: EddsaSignature;
22
24
  nonce: Uint8Array;
23
25
  }): boolean;
24
- /** Builds the status.cn_zk_revocation claim for the signed body (spec 07). */
25
- export declare function buildStatusClaim(commitment: bigint, revocationRegistry: string): StatusClaim;
@@ -4,7 +4,7 @@ exports.generateRevocationSecret = generateRevocationSecret;
4
4
  exports.deriveRevocationCommitment = deriveRevocationCommitment;
5
5
  exports.signCommitmentOwnership = signCommitmentOwnership;
6
6
  exports.verifyCommitmentOwnership = verifyCommitmentOwnership;
7
- exports.buildStatusClaim = buildStatusClaim;
7
+ const issuer_set_1 = require("@coordination-network/issuer-set");
8
8
  const identity_1 = require("@semaphore-protocol/identity");
9
9
  const utils_1 = require("@noble/hashes/utils");
10
10
  /**
@@ -47,11 +47,16 @@ function signCommitmentOwnership(r, nonce) {
47
47
  };
48
48
  }
49
49
  /**
50
- * Issuer-side check: verifies the EdDSA signature over the nonce, recomputes
51
- * the commitment from the public key, and compares it to the claimed one.
50
+ * Issuer-side check: requires a prime-order public key, verifies the EdDSA
51
+ * signature over the nonce, recomputes the commitment from the public key, and
52
+ * compares it to the claimed one. A low-order key is refused because its
53
+ * signatures need no secret.
52
54
  */
53
55
  function verifyCommitmentOwnership(params) {
54
56
  try {
57
+ if (!(0, issuer_set_1.inPrimeOrderSubgroup)(params.publicKey)) {
58
+ return false;
59
+ }
55
60
  if (!identity_1.Identity.verifySignature(nonceToBigint(params.nonce), params.signature, params.publicKey)) {
56
61
  return false;
57
62
  }
@@ -61,12 +66,3 @@ function verifyCommitmentOwnership(params) {
61
66
  return false;
62
67
  }
63
68
  }
64
- /** Builds the status.cn_zk_revocation claim for the signed body (spec 07). */
65
- function buildStatusClaim(commitment, revocationRegistry) {
66
- return {
67
- cn_zk_revocation: {
68
- revocationRegistry,
69
- revocationCommitment: commitment.toString(10)
70
- }
71
- };
72
- }
package/dist/signer.d.ts CHANGED
@@ -1,19 +1,8 @@
1
1
  import { Jwk } from "./types";
2
- /**
3
- * Issuer signing key, KMS-shaped. sign receives the JWS signing input in
4
- * message mode (the service applies SHA-256 itself, never a precomputed
5
- * digest) and returns the raw 64-byte r||s signature.
6
- */
7
- export interface Signer {
2
+ /** Holder P-256 device key backed by a secure element in production. */
3
+ export interface DeviceSigner {
8
4
  getPublicKeyJwk(): Promise<Jwk>;
9
5
  sign(message: Uint8Array): Promise<Uint8Array>;
10
- }
11
- /**
12
- * Holder P-256 device key: the secure element in the app, a software key in
13
- * tests. Same contract as Signer; a separate type because the two keys must
14
- * never be interchangeable in signatures.
15
- */
16
- export interface DeviceSigner extends Signer {
17
6
  /** Signs an already-computed 32-byte digest, without hashing it again. */
18
7
  signDigest(digest: Uint8Array): Promise<Uint8Array>;
19
8
  }
package/dist/types.d.ts CHANGED
@@ -21,31 +21,6 @@ export interface EddsaSignature {
21
21
  R8: [bigint, bigint];
22
22
  S: bigint;
23
23
  }
24
- /**
25
- * The custom status member inside the signed body (spec 07). The commitment
26
- * is issuer-attested and visible to WS1 verifiers by design.
27
- */
28
- export interface StatusClaim {
29
- cn_zk_revocation: {
30
- /** urn:cn:contract: URN of the on-chain revocation registry. */
31
- revocationRegistry: string;
32
- revocationCommitment: string;
33
- };
34
- }
35
- /** The reconstructed claim set of a verified credential. */
36
- export interface ApprovalCredentialClaims {
37
- vct: string;
38
- iss: string;
39
- sub: string;
40
- jti: string;
41
- nbf: number;
42
- exp: number;
43
- cnf: {
44
- jwk: Jwk;
45
- };
46
- status: StatusClaim;
47
- approvalScope: ApprovalScope;
48
- }
49
24
  export interface IssuanceRequest {
50
25
  issuerNetworkId: Hex32;
51
26
  subjectNetworkId: Hex32;
@@ -63,9 +38,6 @@ export interface IssuanceRequest {
63
38
  ownershipSignature: EddsaSignature;
64
39
  };
65
40
  }
66
- export interface SdJwtIssueParams extends IssuanceRequest {
67
- revocationRegistry: string;
68
- }
69
41
  export interface ZkCredentialIssueParams extends IssuanceRequest {
70
42
  identityPublicKey: EddsaPublicKey;
71
43
  }
@@ -99,13 +71,3 @@ export interface SerializedZkCredential {
99
71
  S: string;
100
72
  };
101
73
  }
102
- export type VerifyErrorCode = "MALFORMED" | "ISSUER_NOT_APPROVED" | "KEY_NOT_FOUND" | "PROOF_INVALID" | "EXPIRED" | "NOT_YET_VALID" | "REVOKED";
103
- /** Checks run in spec order (07, verification flow) and the first failure wins. */
104
- export type VerifyResult = {
105
- ok: true;
106
- claims: ApprovalCredentialClaims;
107
- } | {
108
- ok: false;
109
- code: VerifyErrorCode;
110
- message: string;
111
- };
@@ -12,6 +12,12 @@ export interface ExpectedZkPresentation {
12
12
  programme: string;
13
13
  country: string;
14
14
  }
15
+ /**
16
+ * `approvedIssuerRoot` and `revocationRoot` are the proof's public outputs and are
17
+ * not checked here. Check them against the registries before accepting the presentation:
18
+ * the issuer root against the approved-issuer set, the revocation root with the revocation
19
+ * registry's `isValidRoot`.
20
+ */
15
21
  export type ZkPresentationVerifyResult = {
16
22
  ok: true;
17
23
  approvedIssuerRoot: bigint;
@@ -41,5 +47,9 @@ export declare class ZkCredentialProofSystem {
41
47
  destroy(): Promise<void>;
42
48
  }
43
49
  export declare function generateZkPresentationProof(circuit: CompiledCircuit, inputs: ZkPresentationInputs, options?: ZkProofSystemOptions): Promise<ZkPresentationProof>;
50
+ /**
51
+ * Verifies a presentation proof against the expected public inputs and returns the roots
52
+ * from the proof. Check those roots against the registries; see {@link ZkPresentationVerifyResult}.
53
+ */
44
54
  export declare function verifyZkPresentationProof(circuit: CompiledCircuit, proof: ZkPresentationProof, expected: ExpectedZkPresentation, options?: ZkProofSystemOptions): Promise<ZkPresentationVerifyResult>;
45
55
  export {};
package/dist/zk-proof.js CHANGED
@@ -119,6 +119,10 @@ async function generateZkPresentationProof(circuit, inputs, options = {}) {
119
119
  await proofSystem.destroy();
120
120
  }
121
121
  }
122
+ /**
123
+ * Verifies a presentation proof against the expected public inputs and returns the roots
124
+ * from the proof. Check those roots against the registries; see {@link ZkPresentationVerifyResult}.
125
+ */
122
126
  async function verifyZkPresentationProof(circuit, proof, expected, options = {}) {
123
127
  const proofSystem = await ZkCredentialProofSystem.create(circuit, options);
124
128
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coordination-network/credential",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Verifiable credential SDK for the coordination network: issuance, verification, holder binding and revocation helpers.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -30,24 +30,21 @@
30
30
  "test": "jest"
31
31
  },
32
32
  "devDependencies": {
33
- "@coordination-network/zk-artifacts": "^0.0.1",
34
- "@sd-jwt/core": "^0.19.0",
35
- "@sd-jwt/types": "^0.19.0",
33
+ "@coordination-network/zk-artifacts": "^0.0.2",
36
34
  "@types/jest": "^30.0.0",
37
35
  "@types/node": "^24.0.0",
36
+ "@zk-kit/baby-jubjub": "1.0.3",
38
37
  "jest": "^30.4.2",
39
38
  "ts-jest": "^29.4.11",
40
39
  "typescript": "^6.0.3"
41
40
  },
42
41
  "dependencies": {
43
42
  "@aztec/bb.js": "5.0.0",
44
- "@coordination-network/identity": "^0.0.1",
45
- "@coordination-network/issuer-set": "^0.0.1",
43
+ "@coordination-network/identity": "^0.0.2",
44
+ "@coordination-network/issuer-set": "^0.0.2",
46
45
  "@noble/curves": "^1.9.7",
47
46
  "@noble/hashes": "^1.8.0",
48
47
  "@noir-lang/noir_js": "1.0.0-beta.22",
49
- "@sd-jwt/decode": "^0.19.0",
50
- "@sd-jwt/sd-jwt-vc": "^0.19.0",
51
48
  "@semaphore-protocol/identity": "^4.14.3",
52
49
  "poseidon-lite": "0.3.0",
53
50
  "viem": "^2.55.11"
package/src/crypto.ts CHANGED
@@ -3,11 +3,7 @@ import { sha256 } from "@noble/hashes/sha2"
3
3
  import { bytesToHex, randomBytes } from "@noble/hashes/utils"
4
4
  import { base64urlToBytes as strictBase64urlToBytes, bytesToBase64url } from "@coordination-network/identity"
5
5
  import { Jwk } from "./types"
6
- import { DeviceSigner, Signer } from "./signer"
7
-
8
- /** Bridges the KMS-shaped Signer interface, the noble primitives, and the callback shapes @sd-jwt expects. */
9
-
10
- const utf8 = (data: string): Uint8Array => new TextEncoder().encode(data)
6
+ import { DeviceSigner } from "./signer"
11
7
 
12
8
  export { bytesToBase64url }
13
9
 
@@ -74,33 +70,6 @@ export function verifyP256(message: Uint8Array, signature: Uint8Array, publicKey
74
70
  }
75
71
  }
76
72
 
77
- /** Bridges a Signer to the @sd-jwt signer callback (base64url over utf8 input). */
78
- export function createSdJwtSigner(signer: Signer): (data: string) => Promise<string> {
79
- return async (data: string) => bytesToBase64url(await signer.sign(utf8(data)))
80
- }
81
-
82
- /** Builds the @sd-jwt verifier callback from a resolved issuer JWK. */
83
- export function createSdJwtVerifier(jwk: Jwk): (data: string, signature: string) => boolean {
84
- const publicKey = jwkToPublicKeyBytes(jwk)
85
- return (data: string, signature: string) => {
86
- try {
87
- return verifyP256(utf8(data), base64urlToBytes(signature), publicKey)
88
- } catch {
89
- return false
90
- }
91
- }
92
- }
93
-
94
- /** The sha-256 hasher the @sd-jwt config takes. */
95
- export function sdJwtHasher(data: string | ArrayBuffer): Uint8Array {
96
- return sha256(typeof data === "string" ? data : new Uint8Array(data))
97
- }
98
-
99
- /** Hex salts for disclosure digests. */
100
- export function sdJwtSaltGenerator(length: number): string {
101
- return bytesToHex(randomBytes(length))
102
- }
103
-
104
73
  /** RFC 4122 v4 UUID from CSPRNG bytes — node:crypto is unavailable under React Native. */
105
74
  export function randomUuid(): string {
106
75
  const bytes = randomBytes(16)
@@ -115,9 +84,9 @@ export function randomUuid(): string {
115
84
  * Software P-256 signer. The issuer demo and every test use it; production
116
85
  * issuers replace it with a KMS-backed Signer, apps with a secure-element
117
86
  * DeviceSigner. Signs in message mode with low-s, raw 64-byte output —
118
- * exactly the Signer contract.
87
+ * exactly the DeviceSigner contract.
119
88
  */
120
- export class LocalP256Signer implements Signer, DeviceSigner {
89
+ export class LocalP256Signer implements DeviceSigner {
121
90
  private readonly privateKey: Uint8Array
122
91
 
123
92
  constructor(privateKey: Uint8Array) {
package/src/index.ts CHANGED
@@ -11,9 +11,4 @@ export * from "./zk-proof"
11
11
  export * from "./resolver"
12
12
  export * from "./registry-client"
13
13
  export * from "./crypto"
14
- export * from "./decode"
15
- export * from "./profile"
16
- export * from "./issue"
17
- export * from "./verify"
18
- export * from "./present"
19
14
  export * from "./revocation"
@@ -1,4 +1,5 @@
1
1
  import { InvalidBindingInputError, verifyCredentialBinding } from "@coordination-network/identity"
2
+ import { inPrimeOrderSubgroup } from "@coordination-network/issuer-set"
2
3
  import { hexToBytes } from "@noble/hashes/utils"
3
4
  import { Identity } from "@semaphore-protocol/identity"
4
5
  import { CredentialSigner } from "./credential-signer"
@@ -7,13 +8,13 @@ import { jwkToPublicKeyBytes } from "./crypto"
7
8
  import { IssuanceError } from "./errors"
8
9
  import { ApprovalResolver } from "./resolver"
9
10
  import { verifyCommitmentOwnership } from "./revocation"
10
- import { ZkCredential, ZkCredentialIssueParams } from "./types"
11
+ import { ZkCredential, ZkCredentialBody, ZkCredentialIssueParams } from "./types"
11
12
 
12
- export async function issueZkCredential(
13
+ /** Validates an issuance request without signing it. */
14
+ export async function validateZkCredentialIssue(
13
15
  params: ZkCredentialIssueParams,
14
- signer: CredentialSigner,
15
16
  approval: ApprovalResolver
16
- ): Promise<ZkCredential> {
17
+ ): Promise<ZkCredentialBody> {
17
18
  if (!(await approval.isApprovedNetworkMember(params.issuerNetworkId))) {
18
19
  throw new IssuanceError(
19
20
  "ISSUER_NOT_APPROVED",
@@ -24,6 +25,10 @@ export async function issueZkCredential(
24
25
  throw new IssuanceError("INVALID_PARAMS", "validFrom must be before validUntil")
25
26
  }
26
27
 
28
+ if (!inPrimeOrderSubgroup(params.identityPublicKey)) {
29
+ throw new IssuanceError("INVALID_PARAMS", "identity public key is not in the prime-order subgroup")
30
+ }
31
+
27
32
  const holderKeyCommitment = Identity.generateCommitment(params.identityPublicKey)
28
33
  const holderKeyCommitmentBytes = hexToBytes(holderKeyCommitment.toString(16).padStart(64, "0"))
29
34
  let binding: ReturnType<typeof verifyCredentialBinding>
@@ -60,7 +65,7 @@ export async function issueZkCredential(
60
65
  throw new IssuanceError("COMMITMENT_OWNERSHIP_INVALID", "revocation commitment ownership proof failed")
61
66
  }
62
67
 
63
- const body = {
68
+ return {
64
69
  programmeHash: programmeHash(params.approvalScope.programme),
65
70
  countryCode: countryCode(params.approvalScope.country),
66
71
  notBefore: params.validFrom,
@@ -69,10 +74,24 @@ export async function issueZkCredential(
69
74
  holderKeyCommitment,
70
75
  revocationCommitment: params.revocation.commitment
71
76
  }
77
+ }
72
78
 
79
+ /** Signs a request that has already passed {@link validateZkCredentialIssue}. */
80
+ export async function signValidatedZkCredential(
81
+ body: ZkCredentialBody,
82
+ signer: CredentialSigner
83
+ ): Promise<ZkCredential> {
73
84
  return {
74
85
  body,
75
86
  issuerPublicKey: await signer.getPublicKey(),
76
87
  signature: await signer.sign(zkCredentialCommitment(body))
77
88
  }
78
89
  }
90
+
91
+ export async function issueZkCredential(
92
+ params: ZkCredentialIssueParams,
93
+ signer: CredentialSigner,
94
+ approval: ApprovalResolver
95
+ ): Promise<ZkCredential> {
96
+ return signValidatedZkCredential(await validateZkCredentialIssue(params, approval), signer)
97
+ }