@fide.work/fcp 0.0.1-alpha.0

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.
Files changed (78) hide show
  1. package/README.md +18 -0
  2. package/dist/attestation/create.d.ts +173 -0
  3. package/dist/attestation/create.js +179 -0
  4. package/dist/attestation/index.d.ts +7 -0
  5. package/dist/attestation/index.js +7 -0
  6. package/dist/attestation/verify.d.ts +56 -0
  7. package/dist/attestation/verify.js +94 -0
  8. package/dist/broadcasting/config.d.ts +27 -0
  9. package/dist/broadcasting/config.js +22 -0
  10. package/dist/broadcasting/index.d.ts +7 -0
  11. package/dist/broadcasting/index.js +7 -0
  12. package/dist/broadcasting/registry.d.ts +111 -0
  13. package/dist/broadcasting/registry.js +99 -0
  14. package/dist/experimental/attestation/create.d.ts +173 -0
  15. package/dist/experimental/attestation/create.js +188 -0
  16. package/dist/experimental/attestation/index.d.ts +7 -0
  17. package/dist/experimental/attestation/index.js +7 -0
  18. package/dist/experimental/attestation/verify.d.ts +56 -0
  19. package/dist/experimental/attestation/verify.js +94 -0
  20. package/dist/experimental/broadcasting/config.d.ts +27 -0
  21. package/dist/experimental/broadcasting/config.js +22 -0
  22. package/dist/experimental/broadcasting/index.d.ts +7 -0
  23. package/dist/experimental/broadcasting/index.js +7 -0
  24. package/dist/experimental/broadcasting/registry.d.ts +111 -0
  25. package/dist/experimental/broadcasting/registry.js +99 -0
  26. package/dist/experimental/index.d.ts +9 -0
  27. package/dist/experimental/index.js +13 -0
  28. package/dist/experimental/merkle/index.d.ts +6 -0
  29. package/dist/experimental/merkle/index.js +6 -0
  30. package/dist/experimental/merkle/tree.d.ts +72 -0
  31. package/dist/experimental/merkle/tree.js +154 -0
  32. package/dist/experimental/signing/ed25519.d.ts +116 -0
  33. package/dist/experimental/signing/ed25519.js +161 -0
  34. package/dist/experimental/signing/eip191.d.ts +50 -0
  35. package/dist/experimental/signing/eip191.js +96 -0
  36. package/dist/experimental/signing/eip712.d.ts +112 -0
  37. package/dist/experimental/signing/eip712.js +187 -0
  38. package/dist/experimental/signing/index.d.ts +8 -0
  39. package/dist/experimental/signing/index.js +11 -0
  40. package/dist/fide-id/calculateFideId.d.ts +21 -0
  41. package/dist/fide-id/calculateFideId.js +53 -0
  42. package/dist/fide-id/calculateStatementFideId.d.ts +21 -0
  43. package/dist/fide-id/calculateStatementFideId.js +38 -0
  44. package/dist/fide-id/constants.d.ts +43 -0
  45. package/dist/fide-id/constants.js +55 -0
  46. package/dist/fide-id/index.d.ts +10 -0
  47. package/dist/fide-id/index.js +12 -0
  48. package/dist/fide-id/types.d.ts +52 -0
  49. package/dist/fide-id/types.js +5 -0
  50. package/dist/fide-id/utils.d.ts +30 -0
  51. package/dist/fide-id/utils.js +65 -0
  52. package/dist/index.d.ts +11 -0
  53. package/dist/index.js +19 -0
  54. package/dist/merkle/index.d.ts +6 -0
  55. package/dist/merkle/index.js +6 -0
  56. package/dist/merkle/tree.d.ts +72 -0
  57. package/dist/merkle/tree.js +154 -0
  58. package/dist/schema/evaluations.d.ts +31 -0
  59. package/dist/schema/evaluations.js +31 -0
  60. package/dist/schema/index.d.ts +6 -0
  61. package/dist/schema/index.js +6 -0
  62. package/dist/schema/predicates.d.ts +110 -0
  63. package/dist/schema/predicates.js +122 -0
  64. package/dist/signing/ed25519.d.ts +116 -0
  65. package/dist/signing/ed25519.js +161 -0
  66. package/dist/signing/eip191.d.ts +50 -0
  67. package/dist/signing/eip191.js +96 -0
  68. package/dist/signing/eip712.d.ts +112 -0
  69. package/dist/signing/eip712.js +187 -0
  70. package/dist/signing/index.d.ts +8 -0
  71. package/dist/signing/index.js +11 -0
  72. package/dist/statement/build.d.ts +99 -0
  73. package/dist/statement/build.js +71 -0
  74. package/dist/statement/index.d.ts +6 -0
  75. package/dist/statement/index.js +6 -0
  76. package/dist/statement/policy.d.ts +33 -0
  77. package/dist/statement/policy.js +183 -0
  78. package/package.json +64 -0
@@ -0,0 +1,6 @@
1
+ /**
2
+ * FCP SDK - Merkle Tree Module
3
+ *
4
+ * Re-exports all Merkle tree utilities.
5
+ */
6
+ export { buildMerkleTree, verifyMerkleProof } from "./tree.js";
@@ -0,0 +1,72 @@
1
+ /**
2
+ * FCP SDK Merkle Tree Utilities
3
+ * Build and verify Merkle trees for batch attestations
4
+ *
5
+ * Uses SHA-256 for hashing (same as Fide ID derivation).
6
+ * Zero external dependencies - uses native Web Crypto API.
7
+ */
8
+ /**
9
+ * Merkle proof element
10
+ */
11
+ export interface MerkleProofElement {
12
+ /** The sibling hash at this level */
13
+ hash: string;
14
+ /** Position of the sibling: 'left' or 'right' */
15
+ position: 'left' | 'right';
16
+ }
17
+ /**
18
+ * Merkle proof for a specific leaf
19
+ */
20
+ export type MerkleProof = MerkleProofElement[];
21
+ /**
22
+ * Result from building a Merkle tree
23
+ */
24
+ export interface MerkleTreeResult {
25
+ /** The Merkle root (hex string) */
26
+ root: string;
27
+ /** Proofs for each leaf, indexed by leaf value */
28
+ proofs: Map<string, MerkleProof>;
29
+ /** The leaves used to build the tree (normalized) */
30
+ leaves: string[];
31
+ }
32
+ /**
33
+ * Build a Merkle tree from an array of Fide IDs
34
+ *
35
+ * The tree is built bottom-up by iteratively hashing pairs of nodes.
36
+ * If there's an odd number of nodes, the last node is duplicated.
37
+ *
38
+ * @param leaves - Array of statement Fide IDs to include in the tree
39
+ * @returns MerkleTreeResult with root and proofs for each leaf
40
+ * @throws Error if leaves array is empty
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const result = await buildMerkleTree([
45
+ * 'did:fide:0x00abc...',
46
+ * 'did:fide:0x00def...',
47
+ * 'did:fide:0x00ghi...'
48
+ * ]);
49
+ *
50
+ * console.log('Root:', result.root);
51
+ * console.log('Proof for first leaf:', result.proofs.get('did:fide:0x00abc...'));
52
+ * ```
53
+ */
54
+ export declare function buildMerkleTree(leaves: string[]): Promise<MerkleTreeResult>;
55
+ /**
56
+ * Verify that a leaf is part of a Merkle tree given its proof
57
+ *
58
+ * @param leaf - The leaf value to verify in Merkle tree
59
+ * @param proof - The Merkle proof path (array of hashes from leaf to root)
60
+ * @param root - The Merkle tree root hash (0x-prefixed hex)
61
+ * @returns True if the proof is valid
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const isValid = await verifyMerkleProof(
66
+ * 'did:fide:0x00abc...',
67
+ * proof,
68
+ * root
69
+ * );
70
+ * ```
71
+ */
72
+ export declare function verifyMerkleProof(leaf: string, proof: MerkleProof, root: string): Promise<boolean>;
@@ -0,0 +1,154 @@
1
+ /**
2
+ * FCP SDK Merkle Tree Utilities
3
+ * Build and verify Merkle trees for batch attestations
4
+ *
5
+ * Uses SHA-256 for hashing (same as Fide ID derivation).
6
+ * Zero external dependencies - uses native Web Crypto API.
7
+ */
8
+ /**
9
+ * Get the Web Crypto API (works in browsers and Node.js)
10
+ */
11
+ async function getSubtleCrypto() {
12
+ if (globalThis.crypto?.subtle) {
13
+ return globalThis.crypto.subtle;
14
+ }
15
+ const { webcrypto } = await import("node:crypto");
16
+ return webcrypto.subtle;
17
+ }
18
+ /**
19
+ * Hash two values together using SHA-256
20
+ * Sorts inputs to ensure consistent ordering
21
+ */
22
+ async function hashPair(left, right) {
23
+ const subtle = await getSubtleCrypto();
24
+ // Concatenate left + right (already sorted at construction time)
25
+ const combined = left + right;
26
+ const encoder = new TextEncoder();
27
+ const data = encoder.encode(combined);
28
+ const hashBuffer = await subtle.digest('SHA-256', data);
29
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
30
+ return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
31
+ }
32
+ /**
33
+ * Normalize a Fide ID to a consistent hex format for hashing
34
+ * Accepts: "did:fide:0x..." or "0x..."
35
+ * Returns: lowercase hex without prefix
36
+ */
37
+ function normalizeLeaf(fideId) {
38
+ const trimmed = fideId.trim().toLowerCase();
39
+ if (trimmed.startsWith('did:fide:0x')) {
40
+ return trimmed.slice('did:fide:0x'.length);
41
+ }
42
+ if (trimmed.startsWith('0x')) {
43
+ return trimmed.slice(2);
44
+ }
45
+ return trimmed;
46
+ }
47
+ /**
48
+ * Build a Merkle tree from an array of Fide IDs
49
+ *
50
+ * The tree is built bottom-up by iteratively hashing pairs of nodes.
51
+ * If there's an odd number of nodes, the last node is duplicated.
52
+ *
53
+ * @param leaves - Array of statement Fide IDs to include in the tree
54
+ * @returns MerkleTreeResult with root and proofs for each leaf
55
+ * @throws Error if leaves array is empty
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const result = await buildMerkleTree([
60
+ * 'did:fide:0x00abc...',
61
+ * 'did:fide:0x00def...',
62
+ * 'did:fide:0x00ghi...'
63
+ * ]);
64
+ *
65
+ * console.log('Root:', result.root);
66
+ * console.log('Proof for first leaf:', result.proofs.get('did:fide:0x00abc...'));
67
+ * ```
68
+ */
69
+ export async function buildMerkleTree(leaves) {
70
+ if (leaves.length === 0) {
71
+ throw new Error('Cannot build Merkle tree from empty array');
72
+ }
73
+ // Normalize all leaves
74
+ const normalizedLeaves = leaves.map(normalizeLeaf);
75
+ // Initialize proofs map (keyed by original leaf value)
76
+ const proofs = new Map();
77
+ leaves.forEach(leaf => proofs.set(leaf, []));
78
+ // Also map normalized → original for lookup
79
+ const normalizedToOriginal = new Map();
80
+ leaves.forEach((original, i) => {
81
+ normalizedToOriginal.set(normalizedLeaves[i], original);
82
+ });
83
+ // Build tree level by level
84
+ let currentLevel = [...normalizedLeaves];
85
+ // Track which original leaves each node represents
86
+ // At level 0, each node represents itself
87
+ let nodeToLeaves = new Map();
88
+ normalizedLeaves.forEach(leaf => nodeToLeaves.set(leaf, [leaf]));
89
+ while (currentLevel.length > 1) {
90
+ const nextLevel = [];
91
+ const nextNodeToLeaves = new Map();
92
+ for (let i = 0; i < currentLevel.length; i += 2) {
93
+ const left = currentLevel[i];
94
+ const right = i + 1 < currentLevel.length ? currentLevel[i + 1] : left; // Duplicate if odd
95
+ const parent = await hashPair(left, right);
96
+ nextLevel.push(parent);
97
+ // Track which leaves this parent represents
98
+ const leftLeaves = nodeToLeaves.get(left) || [];
99
+ const rightLeaves = nodeToLeaves.get(right) || [];
100
+ nextNodeToLeaves.set(parent, [...leftLeaves, ...rightLeaves]);
101
+ // Add proof elements for all leaves on each side
102
+ // Leaves on the left get right sibling, leaves on the right get left sibling
103
+ for (const leafNorm of leftLeaves) {
104
+ const original = normalizedToOriginal.get(leafNorm);
105
+ const proof = proofs.get(original);
106
+ proof.push({ hash: right, position: 'right' });
107
+ }
108
+ // Only add if right != left (not a duplicate)
109
+ if (left !== right) {
110
+ for (const leafNorm of rightLeaves) {
111
+ const original = normalizedToOriginal.get(leafNorm);
112
+ const proof = proofs.get(original);
113
+ proof.push({ hash: left, position: 'left' });
114
+ }
115
+ }
116
+ }
117
+ currentLevel = nextLevel;
118
+ nodeToLeaves = nextNodeToLeaves;
119
+ }
120
+ return {
121
+ root: currentLevel[0],
122
+ proofs,
123
+ leaves
124
+ };
125
+ }
126
+ /**
127
+ * Verify that a leaf is part of a Merkle tree given its proof
128
+ *
129
+ * @param leaf - The leaf value to verify in Merkle tree
130
+ * @param proof - The Merkle proof path (array of hashes from leaf to root)
131
+ * @param root - The Merkle tree root hash (0x-prefixed hex)
132
+ * @returns True if the proof is valid
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * const isValid = await verifyMerkleProof(
137
+ * 'did:fide:0x00abc...',
138
+ * proof,
139
+ * root
140
+ * );
141
+ * ```
142
+ */
143
+ export async function verifyMerkleProof(leaf, proof, root) {
144
+ let currentHash = normalizeLeaf(leaf);
145
+ for (const element of proof) {
146
+ if (element.position === 'left') {
147
+ currentHash = await hashPair(element.hash, currentHash);
148
+ }
149
+ else {
150
+ currentHash = await hashPair(currentHash, element.hash);
151
+ }
152
+ }
153
+ return currentHash === root;
154
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * FCP SDK Evaluation Method Constants
3
+ */
4
+ /**
5
+ * Common Fide evaluation methods.
6
+ *
7
+ * These are used as predicates in Evaluation (0xe5) statements.
8
+ */
9
+ export declare const FIDE_EVALUATION_METHODS: {
10
+ /**
11
+ * Trust in an identity resolution (owl:sameAs) claim.
12
+ * Evaluates a Statement about owl:sameAs.
13
+ */
14
+ readonly aliasResolutionTrust: "https://github.com/fide-work/evaluation-methods/alias-resolution-trust/v1";
15
+ /**
16
+ * Trust in an owl:sameAs claim specifically for Person entities.
17
+ */
18
+ readonly owlSameAsPerson: "https://github.com/fide-work/evaluation-methods/owl-sameas-person/v1";
19
+ /**
20
+ * Trust in an owl:sameAs claim specifically for Organization entities.
21
+ */
22
+ readonly owlSameAsOrganization: "https://github.com/fide-work/evaluation-methods/owl-sameas-organization/v1";
23
+ /**
24
+ * Trust in the accuracy of a statement.
25
+ */
26
+ readonly statementAccuracy: "https://github.com/fide-work/evaluation-methods/statement-accuracy/v1";
27
+ /**
28
+ * Trust in bridging consensus.
29
+ */
30
+ readonly bridgingConsensus: "https://github.com/fide-work/evaluation-methods/bridging-consensus/v1";
31
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * FCP SDK Evaluation Method Constants
3
+ */
4
+ /**
5
+ * Common Fide evaluation methods.
6
+ *
7
+ * These are used as predicates in Evaluation (0xe5) statements.
8
+ */
9
+ export const FIDE_EVALUATION_METHODS = {
10
+ /**
11
+ * Trust in an identity resolution (owl:sameAs) claim.
12
+ * Evaluates a Statement about owl:sameAs.
13
+ */
14
+ aliasResolutionTrust: 'https://github.com/fide-work/evaluation-methods/alias-resolution-trust/v1',
15
+ /**
16
+ * Trust in an owl:sameAs claim specifically for Person entities.
17
+ */
18
+ owlSameAsPerson: 'https://github.com/fide-work/evaluation-methods/owl-sameas-person/v1',
19
+ /**
20
+ * Trust in an owl:sameAs claim specifically for Organization entities.
21
+ */
22
+ owlSameAsOrganization: 'https://github.com/fide-work/evaluation-methods/owl-sameas-organization/v1',
23
+ /**
24
+ * Trust in the accuracy of a statement.
25
+ */
26
+ statementAccuracy: 'https://github.com/fide-work/evaluation-methods/statement-accuracy/v1',
27
+ /**
28
+ * Trust in bridging consensus.
29
+ */
30
+ bridgingConsensus: 'https://github.com/fide-work/evaluation-methods/bridging-consensus/v1'
31
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * FCP SDK - Schema Module
3
+ *
4
+ * Re-exports all schema utilities.
5
+ */
6
+ export { SCHEMA_PREDICATES, PROV_PREDICATES, OWL_PREDICATES, SEC_PREDICATES, expandPredicateIdentifier, type PredicateNamespace } from "./predicates.js";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * FCP SDK - Schema Module
3
+ *
4
+ * Re-exports all schema utilities.
5
+ */
6
+ export { SCHEMA_PREDICATES, PROV_PREDICATES, OWL_PREDICATES, SEC_PREDICATES, expandPredicateIdentifier } from "./predicates.js";
@@ -0,0 +1,110 @@
1
+ /**
2
+ * FCP SDK Schema Utilities
3
+ *
4
+ * Common predicate constants and helpers for working with FCP schema predicates.
5
+ *
6
+ * Note: The SDK handles deterministic JSON serialization (RFC 8785) internally
7
+ * following the json-stable-stringify philosophy - using manually ordered keys
8
+ * for all Fide ID calculations. No external dependencies are required.
9
+ */
10
+ /**
11
+ * Expand shorthand predicate identifiers to full canonical URLs.
12
+ * `calculateFideId` stays dumb; this provides a convenience layer for predicates.
13
+ *
14
+ * Accepts shorthand (e.g. `schema:name`, `owl:sameAs`) and returns the full IRI.
15
+ * Pass-through for strings that already look like full URLs (contain `://`).
16
+ *
17
+ * @param predicate - Shorthand (e.g. `schema:name`) or full URL
18
+ * @returns Full canonical URL (e.g. `https://schema.org/name`)
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * expandPredicateIdentifier('schema:name') // 'https://schema.org/name'
23
+ * expandPredicateIdentifier('owl:sameAs') // 'https://www.w3.org/2002/07/owl#sameAs'
24
+ * expandPredicateIdentifier('https://schema.org/name') // unchanged
25
+ * ```
26
+ */
27
+ export declare function expandPredicateIdentifier(predicate: string): string;
28
+ /**
29
+ * Predicate namespace identifiers.
30
+ *
31
+ * @remarks
32
+ * Identifies which ontology namespace a predicate belongs to:
33
+ * - `schema`: Schema.org predicates for common attributes and relationships
34
+ * - `prov`: PROV-O (Provenance Ontology) predicates for tracking lineage
35
+ * - `owl`: OWL (Web Ontology Language) predicates for ontology relationships
36
+ * - `sec`: W3C Security Vocabulary predicates for access control
37
+ */
38
+ export type PredicateNamespace = 'schema' | 'prov' | 'owl' | 'sec';
39
+ /**
40
+ * Common Schema.org predicates.
41
+ *
42
+ * These are commonly used predicates in FCP statements. For the complete list,
43
+ * see [Schema.org](https://schema.org/).
44
+ *
45
+ * @remarks
46
+ * This is a record of predicate strings following the `schema:` namespace convention.
47
+ * Pass directly to functions expecting predicate strings.
48
+ */
49
+ export declare const SCHEMA_PREDICATES: {
50
+ readonly name: "schema:name";
51
+ readonly description: "schema:description";
52
+ readonly type: "schema:type";
53
+ readonly url: "schema:url";
54
+ readonly image: "schema:image";
55
+ readonly worksFor: "schema:worksFor";
56
+ readonly memberOf: "schema:memberOf";
57
+ readonly parentOrganization: "schema:parentOrganization";
58
+ readonly knows: "schema:knows";
59
+ readonly follows: "schema:follows";
60
+ readonly actionStatus: "schema:actionStatus";
61
+ readonly identifier: "schema:identifier";
62
+ readonly sameAs: "schema:sameAs";
63
+ };
64
+ /**
65
+ * PROV-O (Provenance Ontology) predicates.
66
+ *
67
+ * Used for tracking provenance and lineage in FCP statements.
68
+ *
69
+ * @remarks
70
+ * This is a record of predicate strings following the `prov:` namespace convention.
71
+ * Pass directly to functions expecting predicate strings.
72
+ */
73
+ export declare const PROV_PREDICATES: {
74
+ readonly wasGeneratedBy: "prov:wasGeneratedBy";
75
+ readonly wasDerivedFrom: "prov:wasDerivedFrom";
76
+ readonly wasAssociatedWith: "prov:wasAssociatedWith";
77
+ readonly wasAttributedTo: "prov:wasAttributedTo";
78
+ readonly wasRevisionOf: "prov:wasRevisionOf";
79
+ readonly wasQuotedFrom: "prov:wasQuotedFrom";
80
+ readonly actedOnBehalfOf: "prov:actedOnBehalfOf";
81
+ };
82
+ /**
83
+ * OWL (Web Ontology Language) predicates.
84
+ *
85
+ * Used for ontology relationships.
86
+ *
87
+ * @remarks
88
+ * This is a record of predicate strings following the `owl:` namespace convention.
89
+ * Pass directly to functions expecting predicate strings.
90
+ */
91
+ export declare const OWL_PREDICATES: {
92
+ readonly sameAs: "owl:sameAs";
93
+ readonly differentFrom: "owl:differentFrom";
94
+ readonly equivalentClass: "owl:equivalentClass";
95
+ readonly equivalentProperty: "owl:equivalentProperty";
96
+ };
97
+ /**
98
+ * W3C Security Vocabulary predicates.
99
+ *
100
+ * Used for security and access control relationships.
101
+ *
102
+ * @remarks
103
+ * This is a record of predicate strings following the `sec:` namespace convention.
104
+ * Pass directly to functions expecting predicate strings.
105
+ */
106
+ export declare const SEC_PREDICATES: {
107
+ readonly controller: "sec:controller";
108
+ readonly owner: "sec:owner";
109
+ readonly authorizedBy: "sec:authorizedBy";
110
+ };
@@ -0,0 +1,122 @@
1
+ /**
2
+ * FCP SDK Schema Utilities
3
+ *
4
+ * Common predicate constants and helpers for working with FCP schema predicates.
5
+ *
6
+ * Note: The SDK handles deterministic JSON serialization (RFC 8785) internally
7
+ * following the json-stable-stringify philosophy - using manually ordered keys
8
+ * for all Fide ID calculations. No external dependencies are required.
9
+ */
10
+ /** Prefix to canonical base URL. Schema uses /, others use #. */
11
+ const PREDICATE_NAMESPACES = {
12
+ schema: "https://schema.org/",
13
+ owl: "https://www.w3.org/2002/07/owl#",
14
+ prov: "https://www.w3.org/ns/prov#",
15
+ sec: "https://w3id.org/security#",
16
+ skos: "https://www.w3.org/2004/02/skos/core#"
17
+ };
18
+ /**
19
+ * Expand shorthand predicate identifiers to full canonical URLs.
20
+ * `calculateFideId` stays dumb; this provides a convenience layer for predicates.
21
+ *
22
+ * Accepts shorthand (e.g. `schema:name`, `owl:sameAs`) and returns the full IRI.
23
+ * Pass-through for strings that already look like full URLs (contain `://`).
24
+ *
25
+ * @param predicate - Shorthand (e.g. `schema:name`) or full URL
26
+ * @returns Full canonical URL (e.g. `https://schema.org/name`)
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * expandPredicateIdentifier('schema:name') // 'https://schema.org/name'
31
+ * expandPredicateIdentifier('owl:sameAs') // 'https://www.w3.org/2002/07/owl#sameAs'
32
+ * expandPredicateIdentifier('https://schema.org/name') // unchanged
33
+ * ```
34
+ */
35
+ export function expandPredicateIdentifier(predicate) {
36
+ if (predicate.includes("://"))
37
+ return predicate;
38
+ const colon = predicate.indexOf(":");
39
+ if (colon < 1)
40
+ return predicate;
41
+ const prefix = predicate.slice(0, colon);
42
+ const base = PREDICATE_NAMESPACES[prefix];
43
+ if (!base)
44
+ return predicate;
45
+ return base + predicate.slice(colon + 1);
46
+ }
47
+ /**
48
+ * Common Schema.org predicates.
49
+ *
50
+ * These are commonly used predicates in FCP statements. For the complete list,
51
+ * see [Schema.org](https://schema.org/).
52
+ *
53
+ * @remarks
54
+ * This is a record of predicate strings following the `schema:` namespace convention.
55
+ * Pass directly to functions expecting predicate strings.
56
+ */
57
+ export const SCHEMA_PREDICATES = {
58
+ // Attributes
59
+ name: 'schema:name',
60
+ description: 'schema:description',
61
+ type: 'schema:type',
62
+ url: 'schema:url',
63
+ image: 'schema:image',
64
+ // Relationships
65
+ worksFor: 'schema:worksFor',
66
+ memberOf: 'schema:memberOf',
67
+ parentOrganization: 'schema:parentOrganization',
68
+ knows: 'schema:knows',
69
+ follows: 'schema:follows',
70
+ // Actions
71
+ actionStatus: 'schema:actionStatus',
72
+ // Other
73
+ identifier: 'schema:identifier',
74
+ sameAs: 'schema:sameAs'
75
+ };
76
+ /**
77
+ * PROV-O (Provenance Ontology) predicates.
78
+ *
79
+ * Used for tracking provenance and lineage in FCP statements.
80
+ *
81
+ * @remarks
82
+ * This is a record of predicate strings following the `prov:` namespace convention.
83
+ * Pass directly to functions expecting predicate strings.
84
+ */
85
+ export const PROV_PREDICATES = {
86
+ wasGeneratedBy: 'prov:wasGeneratedBy',
87
+ wasDerivedFrom: 'prov:wasDerivedFrom',
88
+ wasAssociatedWith: 'prov:wasAssociatedWith',
89
+ wasAttributedTo: 'prov:wasAttributedTo',
90
+ wasRevisionOf: 'prov:wasRevisionOf',
91
+ wasQuotedFrom: 'prov:wasQuotedFrom',
92
+ actedOnBehalfOf: 'prov:actedOnBehalfOf'
93
+ };
94
+ /**
95
+ * OWL (Web Ontology Language) predicates.
96
+ *
97
+ * Used for ontology relationships.
98
+ *
99
+ * @remarks
100
+ * This is a record of predicate strings following the `owl:` namespace convention.
101
+ * Pass directly to functions expecting predicate strings.
102
+ */
103
+ export const OWL_PREDICATES = {
104
+ sameAs: 'owl:sameAs',
105
+ differentFrom: 'owl:differentFrom',
106
+ equivalentClass: 'owl:equivalentClass',
107
+ equivalentProperty: 'owl:equivalentProperty'
108
+ };
109
+ /**
110
+ * W3C Security Vocabulary predicates.
111
+ *
112
+ * Used for security and access control relationships.
113
+ *
114
+ * @remarks
115
+ * This is a record of predicate strings following the `sec:` namespace convention.
116
+ * Pass directly to functions expecting predicate strings.
117
+ */
118
+ export const SEC_PREDICATES = {
119
+ controller: 'sec:controller',
120
+ owner: 'sec:owner',
121
+ authorizedBy: 'sec:authorizedBy'
122
+ };
@@ -0,0 +1,116 @@
1
+ /**
2
+ * FCP SDK Signing Utilities
3
+ * Ed25519 key generation and signing using native Web Crypto API
4
+ */
5
+ /**
6
+ * Ed25519 Key Pair
7
+ */
8
+ export interface Ed25519KeyPair {
9
+ publicKey: CryptoKey;
10
+ privateKey: CryptoKey;
11
+ }
12
+ /**
13
+ * Exported Ed25519 Keys (hex strings)
14
+ */
15
+ export interface ExportedEd25519Keys {
16
+ publicKeyHex: string;
17
+ privateKeyHex: string;
18
+ address: string;
19
+ }
20
+ /**
21
+ * Generate a new Ed25519 key pair for signing
22
+ *
23
+ * Uses native Web Crypto API - no external dependencies required.
24
+ *
25
+ * @returns Promise resolving to a CryptoKey pair
26
+ *
27
+ * @remarks
28
+ * This is a zero-dependency function that works in both Node.js and browsers.
29
+ * The generated key pair can be exported as hex strings using {@link exportEd25519Keys}.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const keyPair = await generateEd25519KeyPair();
34
+ * const exported = await exportEd25519Keys(keyPair);
35
+ * console.log('Address:', exported.address);
36
+ * ```
37
+ */
38
+ export declare function generateEd25519KeyPair(): Promise<Ed25519KeyPair>;
39
+ /**
40
+ * Export Ed25519 keys as hex strings
41
+ *
42
+ * @param keyPair - The Ed25519 key pair (JWK format)
43
+ * @returns Exported keys with public key, private key, and derived address
44
+ *
45
+ * @remarks
46
+ * Keys are exported in standard formats:
47
+ * - Public key: SubjectPublicKeyInfo (SPKI) format as hex
48
+ * - Private key: PKCS8 format as hex
49
+ * - Address: Derived from the raw public key bytes (last 32 bytes of SPKI key)
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * const keyPair = await generateEd25519KeyPair();
54
+ * const { publicKeyHex, privateKeyHex, address } = await exportEd25519Keys(keyPair);
55
+ * ```
56
+ */
57
+ export declare function exportEd25519Keys(keyPair: Ed25519KeyPair): Promise<ExportedEd25519Keys>;
58
+ /**
59
+ * Import Ed25519 keys from hex strings
60
+ *
61
+ * @param publicKeyHex - Public key in hex format (SPKI)
62
+ * @param privateKeyHex - Private key in hex format (PKCS8)
63
+ * @returns Imported CryptoKey pair
64
+ *
65
+ * @remarks
66
+ * Keys must be in standard formats:
67
+ * - Public key: SubjectPublicKeyInfo (SPKI) format as hex
68
+ * - Private key: PKCS8 format as hex
69
+ *
70
+ * Use this to restore keys previously exported with {@link exportEd25519Keys}.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const keyPair = await importEd25519Keys(publicKeyHex, privateKeyHex);
75
+ * ```
76
+ */
77
+ export declare function importEd25519Keys(publicKeyHex: string, privateKeyHex: string): Promise<Ed25519KeyPair>;
78
+ /**
79
+ * Sign data using Ed25519 private key
80
+ *
81
+ * @param data - The data/message to sign or verify (hex string for EIP standards, plaintext for EIP-191)
82
+ * @param privateKey - The Ed25519 key pair (JWK format)
83
+ * @returns Hex-encoded signature
84
+ *
85
+ * @remarks
86
+ * This function:
87
+ * - UTF-8 encodes the input data
88
+ * - Signs using the Ed25519 algorithm
89
+ * - Returns the signature as a hex string
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const signature = await signEd25519("Hello, world!", keyPair.privateKey);
94
+ * ```
95
+ */
96
+ export declare function signEd25519(data: string, privateKey: CryptoKey): Promise<string>;
97
+ /**
98
+ * Verify an Ed25519 signature
99
+ *
100
+ * @param data - The data/message to sign or verify (hex string for EIP standards, plaintext for EIP-191)
101
+ * @param signatureHex - The cryptographic signature (0x-prefixed hex string)
102
+ * @param publicKey - The Ed25519 key pair (JWK format)
103
+ * @returns True if signature is valid
104
+ *
105
+ * @remarks
106
+ * This function:
107
+ * - UTF-8 encodes the input data
108
+ * - Verifies the hex-encoded signature using the Ed25519 algorithm
109
+ * - Returns true only if the signature is cryptographically valid
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * const isValid = await verifyEd25519("Hello, world!", signature, keyPair.publicKey);
114
+ * ```
115
+ */
116
+ export declare function verifyEd25519(data: string, signatureHex: string, publicKey: CryptoKey): Promise<boolean>;