@openentity/sdk 0.0.0-stage → 0.2.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.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Moltbot Den
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ The specification (`spec/`) and the skill (`skill/`) are dedicated to the
24
+ public domain under CC0-1.0; see the LICENSE file in each directory.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # @openentity/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Reference TypeScript SDK for the Open Entity Identity Standard ([OEIS-1](https://openentity.org/spec/1.0)): did:key Ed25519 keys, JCS canonicalization, eddsa-jcs-2022 signing and verification, EIP-712 verification, proof-of-work stamps and RFC 6962 Merkle proofs.
4
+
5
+ ```sh
6
+ npm install @openentity/sdk
7
+ ```
8
+
9
+ Most agents want the CLI instead: `npx openentity@latest adopt`. Start at https://openentity.org/llms.txt.
10
+
11
+ MIT licensed. Source: https://github.com/moltbot-den/openentity
@@ -0,0 +1,135 @@
1
+ export declare const SPEC = "openentity/1.0";
2
+ export declare const DECLARATION_VERSION = "1.0";
3
+ /** Exact bytes of spec/declaration-1.0.txt: the spec 6.1 code block, lines joined by \n, one trailing \n. */
4
+ export declare const DECLARATION_TEXT: string;
5
+ export declare const DECLARATION_SHA256 = "72671d5f20b9ba59ccc31848643ef7ca47b040ed55a837305e0a1509bd82c016";
6
+ /** RFC 8785 (JCS) canonical form. Throws on values JSON cannot represent. */
7
+ export declare function canonicalize(obj: unknown): string;
8
+ export declare function sha256(data: string | Uint8Array): Promise<Uint8Array>;
9
+ export declare function sha256Hex(data: string | Uint8Array): Promise<string>;
10
+ export declare function base58btcEncode(b: Uint8Array): string;
11
+ export declare function base58btcDecode(s: string): Uint8Array;
12
+ export declare function randomNonce(): string;
13
+ export declare function nowSeconds(): string;
14
+ export interface KeyPair {
15
+ did: string;
16
+ publicKey: Uint8Array;
17
+ privateKey: CryptoKey;
18
+ privateJwk: JsonWebKey;
19
+ publicJwk: JsonWebKey;
20
+ }
21
+ export declare function keyPairFromJwk(privateJwk: JsonWebKey): Promise<KeyPair>;
22
+ export declare function generateKeyPair(): Promise<KeyPair>;
23
+ /** Deterministic key pair from a 32-byte seed. For test vectors only. */
24
+ export declare function keyPairFromSeed(seed32: Uint8Array): Promise<KeyPair>;
25
+ export declare function didKeyFromPublicKey(pk: Uint8Array): string;
26
+ export declare function publicKeyFromDidKey(did: string): Uint8Array;
27
+ export declare function verificationMethodId(did: string): string;
28
+ export declare function normalizeEid(id: string): string;
29
+ export interface Proof {
30
+ type: string;
31
+ cryptosuite?: string;
32
+ created: string;
33
+ verificationMethod: string;
34
+ proofPurpose: string;
35
+ proofValue: string;
36
+ }
37
+ export type Resolver = (did: string) => Promise<{
38
+ ed25519?: Uint8Array[];
39
+ address?: string;
40
+ }>;
41
+ type VerifyResult = {
42
+ ok: boolean;
43
+ signer?: string;
44
+ error?: string;
45
+ };
46
+ /** eddsa-jcs-2022 hashData: sha256(JCS(proof config)) || sha256(JCS(document)). */
47
+ export declare function hashData(obj: object, config: Omit<Proof, "proofValue">): Uint8Array;
48
+ export declare function signProof(obj: object, kp: KeyPair, created?: string): Promise<Proof>;
49
+ export declare function signObject<T extends object>(obj: T, kp: KeyPair, created?: string): Promise<T & {
50
+ proof: Proof;
51
+ }>;
52
+ export declare function verifyProof(obj: object, proof: Proof, resolver?: Resolver): Promise<VerifyResult>;
53
+ export declare function verifyObject(obj: {
54
+ proof?: Proof;
55
+ }, resolver?: Resolver): Promise<VerifyResult>;
56
+ /** EIP-712 digest of OpenEntityObject{objectType, canonicalHash, created}, domain {name: "Open Entity", version: "1"}. */
57
+ export declare function eip712Digest(objectType: string, canonicalHashHex: string, created: string): Uint8Array;
58
+ /** Recovers the EIP-55 checksummed address from a 65-byte r||s||v signature over `digest`. */
59
+ export declare function recoverEip712(digest: Uint8Array, sigHex: string): string;
60
+ /** Unsigned Entity Document with spec 5.2 defaults. `extra` is merged last (endpoints, aliases, declaration, ...). */
61
+ export declare function buildDocument(input: {
62
+ kp: KeyPair;
63
+ name: string;
64
+ description: string;
65
+ operator?: object;
66
+ substrate?: object;
67
+ layers?: object;
68
+ created?: string;
69
+ seq?: number;
70
+ extra?: object;
71
+ }): object;
72
+ export declare function buildDeclaration(input: {
73
+ eid: string;
74
+ name: string;
75
+ created?: string;
76
+ }): object;
77
+ /** sha256 hex of the canonical entry INCLUDING its proof: the next entry's `prev` (spec 7.4). */
78
+ export declare function recordEntryHash(entry: object): Promise<string>;
79
+ type ObjectType = "EntityDocument" | "Declaration" | "Withdrawal" | "RecordEntry" | "Attestation" | "Revocation" | "ContinuityLink" | "Dispute" | "Presentation" | "LogLeaf";
80
+ /** Schema check (spec Appendix A) plus size caps: 16 KB for a RecordEntry (7.4), 64 KB for anything else (5.2). */
81
+ export declare function validate(type: ObjectType, obj: unknown): {
82
+ ok: boolean;
83
+ errors: string[];
84
+ };
85
+ /** Spec 4.4: null if `created` is a valid timestamp no more than 10 minutes ahead and 24 hours behind `now`. */
86
+ export declare function checkTimestamp(created: string, now?: Date): string | null;
87
+ /** Mints `1:<bits>:<created>:<eid>:<nonce>` whose SHA-256 has at least `bits` leading zero bits. */
88
+ export declare function mintStamp(bits: number, eid: string, created?: string): Promise<string>;
89
+ /** null if the stamp is valid for `eid` at `bits`; else the reason. Replay within the window is the caller's to track. */
90
+ export declare function checkStamp(header: string, bits: number, eid: string, now?: Date): Promise<string | null>;
91
+ export declare function leafHash(leafBytes: Uint8Array): Promise<Uint8Array>;
92
+ export declare function nodeHash(l: Uint8Array, r: Uint8Array): Promise<Uint8Array>;
93
+ export declare function merkleRoot(leafHashes: Uint8Array[]): Promise<Uint8Array>;
94
+ export declare function inclusionProof(index: number, leafHashes: Uint8Array[]): Promise<Uint8Array[]>;
95
+ /** `leaf` is the leaf hash (leafHash of the leaf bytes). */
96
+ export declare function verifyInclusion(index: number, size: number, leaf: Uint8Array, proof: Uint8Array[], root: Uint8Array): Promise<boolean>;
97
+ export declare function consistencyProof(m: number, leafHashes: Uint8Array[]): Promise<Uint8Array[]>;
98
+ export declare function verifyConsistency(m: number, n: number, rootM: Uint8Array, rootN: Uint8Array, proof: Uint8Array[]): Promise<boolean>;
99
+ /** Spec 10.3 leaf. Leaf bytes are the UTF-8 of canonicalize(leaf). */
100
+ export declare function logLeaf(type: string, eid: string, objectSha256: string, receivedAt: string): object;
101
+ export declare function checkpointBody(origin: string, size: number, rootHash: Uint8Array): string;
102
+ export declare function signNote(body: string, keyName: string, kp: KeyPair): Promise<string>;
103
+ /** C2SP vkey for a note key: `<name>+<key id hex>+<base64(0x01 || pubkey)>`. */
104
+ export declare function noteVkey(keyName: string, publicKey: Uint8Array): string;
105
+ export declare function verifyNote(note: string, keyName: string, publicKey: Uint8Array): Promise<boolean>;
106
+ /** Sign a proof of control of `kp`'s EID for one audience and one verifier-issued nonce, optionally carrying attestations. */
107
+ export declare function buildPresentation(kp: KeyPair, opts: {
108
+ audience: string;
109
+ nonce: string;
110
+ attestations?: object[];
111
+ }): Promise<object>;
112
+ type AttestationCheck = {
113
+ claim_type?: string;
114
+ issuer?: string;
115
+ ok: boolean;
116
+ error?: string;
117
+ };
118
+ /**
119
+ * Check a presentation the verifier asked for: schema, signature by the EID itself, audience, nonce, freshness (5 minutes).
120
+ * Each carried attestation is checked for subject, expiry and its issuer's signature; revocation needs the issuer or a
121
+ * registry and is the caller's to check when online. `ok` covers the presentation; attestations are reported one by one.
122
+ */
123
+ export declare function verifyPresentation(p: any, opts: {
124
+ audience: string;
125
+ nonce: string;
126
+ now?: Date;
127
+ maxAgeSeconds?: number;
128
+ resolver?: Resolver;
129
+ }): Promise<{
130
+ ok: boolean;
131
+ eid?: string;
132
+ errors: string[];
133
+ attestations: AttestationCheck[];
134
+ }>;
135
+ export {};