11import * as proto from "@trinsic/okapi-proto" ;
2+
23export * from "@trinsic/okapi-proto" ;
34
45// eslint-disable-next-line @typescript-eslint/no-explicit-any
56let native : any ;
67let initalized = false ;
8+
79async function initialize ( ) {
8- if ( ! initalized ) {
9- native = await import ( "@trinsic/okapi-web" ) ;
10- initalized = true ;
11- }
10+ if ( ! initalized ) {
11+ native = await import ( "@trinsic/okapi-web" ) ;
12+ initalized = true ;
13+ }
1214}
1315
1416export class DIDKey {
15- static async generate (
16- request : proto . GenerateKeyRequest
17- ) : Promise < proto . GenerateKeyResponse > {
18- await initialize ( ) ;
19-
20- return proto . GenerateKeyResponse . deserializeBinary (
21- native . didkey_generate ( request . serializeBinary ( ) )
22- ) ;
23- }
24- static async resolve (
25- request : proto . ResolveRequest
26- ) : Promise < proto . ResolveResponse > {
27- await initialize ( ) ;
28-
29- return proto . ResolveResponse . deserializeBinary (
30- native . didkey_resolve ( request . serializeBinary ( ) )
31- ) ;
32- }
17+ static async generate ( request : proto . GenerateKeyRequest ) : Promise < proto . GenerateKeyResponse > {
18+ await initialize ( ) ;
19+
20+ return proto . GenerateKeyResponse . deserializeBinary ( native . didkey_generate ( request . serializeBinary ( ) ) ) ;
21+ }
22+
23+ static async resolve ( request : proto . ResolveRequest ) : Promise < proto . ResolveResponse > {
24+ await initialize ( ) ;
25+
26+ return proto . ResolveResponse . deserializeBinary ( native . didkey_resolve ( request . serializeBinary ( ) ) ) ;
27+ }
3328}
3429
3530export class DIDComm {
36- static async pack ( request : proto . PackRequest ) : Promise < proto . PackResponse > {
37- await initialize ( ) ;
38-
39- return proto . PackResponse . deserializeBinary (
40- native . didcomm_pack ( request . serializeBinary ( ) )
41- ) ;
42- }
43- static async unpack (
44- request : proto . UnpackRequest
45- ) : Promise < proto . UnpackResponse > {
46- await initialize ( ) ;
47-
48- return proto . UnpackResponse . deserializeBinary (
49- native . didcomm_unpack ( request . serializeBinary ( ) )
50- ) ;
51- }
52- static async sign ( request : proto . SignRequest ) : Promise < proto . SignResponse > {
53- await initialize ( ) ;
54-
55- return proto . SignResponse . deserializeBinary (
56- native . didcomm_sign ( request . serializeBinary ( ) )
57- ) ;
58- }
59- static async verify (
60- request : proto . VerifyRequest
61- ) : Promise < proto . VerifyResponse > {
62- await initialize ( ) ;
63-
64- return proto . VerifyResponse . deserializeBinary (
65- native . didcomm_verify ( request . serializeBinary ( ) )
66- ) ;
67- }
31+ static async pack ( request : proto . PackRequest ) : Promise < proto . PackResponse > {
32+ await initialize ( ) ;
33+
34+ return proto . PackResponse . deserializeBinary ( native . didcomm_pack ( request . serializeBinary ( ) ) ) ;
35+ }
36+
37+ static async unpack ( request : proto . UnpackRequest ) : Promise < proto . UnpackResponse > {
38+ await initialize ( ) ;
39+
40+ return proto . UnpackResponse . deserializeBinary ( native . didcomm_unpack ( request . serializeBinary ( ) ) ) ;
41+ }
42+
43+ static async sign ( request : proto . SignRequest ) : Promise < proto . SignResponse > {
44+ await initialize ( ) ;
45+
46+ return proto . SignResponse . deserializeBinary ( native . didcomm_sign ( request . serializeBinary ( ) ) ) ;
47+ }
48+
49+ static async verify ( request : proto . VerifyRequest ) : Promise < proto . VerifyResponse > {
50+ await initialize ( ) ;
51+
52+ return proto . VerifyResponse . deserializeBinary ( native . didcomm_verify ( request . serializeBinary ( ) ) ) ;
53+ }
6854}
6955
7056export class LdProofs {
71- static async generate (
72- request : proto . CreateProofRequest
73- ) : Promise < proto . CreateProofResponse > {
74- await initialize ( ) ;
75-
76- return proto . CreateProofResponse . deserializeBinary (
77- native . ldproofs_create_proof ( request . serializeBinary ( ) )
78- ) ;
79- }
80- static async convert (
81- request : proto . VerifyProofRequest
82- ) : Promise < proto . VerifyProofResponse > {
83- await initialize ( ) ;
84-
85- return proto . VerifyProofResponse . deserializeBinary (
86- native . ldproofs_verify_proof ( request . serializeBinary ( ) )
87- ) ;
88- }
57+ static async generate ( request : proto . CreateProofRequest ) : Promise < proto . CreateProofResponse > {
58+ await initialize ( ) ;
59+
60+ return proto . CreateProofResponse . deserializeBinary ( native . ldproofs_create_proof ( request . serializeBinary ( ) ) ) ;
61+ }
62+
63+ static async convert ( request : proto . VerifyProofRequest ) : Promise < proto . VerifyProofResponse > {
64+ await initialize ( ) ;
65+
66+ return proto . VerifyProofResponse . deserializeBinary ( native . ldproofs_verify_proof ( request . serializeBinary ( ) ) ) ;
67+ }
8968}
9069
9170export class Oberon {
92- static async createKey (
93- request : proto . CreateOberonKeyRequest
94- ) : Promise < proto . CreateOberonKeyResponse > {
95- await initialize ( ) ;
96- return proto . CreateOberonKeyResponse . deserializeBinary (
97- native . oberon_create_key ( request . serializeBinary ( ) )
98- ) ;
99- }
100- static async createToken (
101- request : proto . CreateOberonTokenRequest
102- ) : Promise < proto . CreateOberonTokenResponse > {
103- await initialize ( ) ;
104- return proto . CreateOberonTokenResponse . deserializeBinary (
105- native . oberon_create_token ( request . serializeBinary ( ) )
106- ) ;
107- }
108- static async createProof (
109- request : proto . CreateOberonProofRequest
110- ) : Promise < proto . CreateOberonProofResponse > {
111- await initialize ( ) ;
112- return proto . CreateOberonProofResponse . deserializeBinary (
113- native . oberon_create_proof ( request . serializeBinary ( ) )
114- ) ;
115- }
116- static async verifyProof (
117- request : proto . VerifyOberonProofRequest
118- ) : Promise < proto . VerifyOberonProofResponse > {
119- await initialize ( ) ;
120- return proto . VerifyOberonProofResponse . deserializeBinary (
121- native . oberon_verify_proof ( request . serializeBinary ( ) )
122- ) ;
123- }
124- static async blindToken (
125- request : proto . BlindOberonTokenRequest
126- ) : Promise < proto . BlindOberonTokenResponse > {
127- await initialize ( ) ;
128- return proto . BlindOberonTokenResponse . deserializeBinary (
129- native . oberon_blind_token ( request . serializeBinary ( ) )
130- ) ;
131- }
132- static async unblindToken (
133- request : proto . UnBlindOberonTokenRequest
134- ) : Promise < proto . UnBlindOberonTokenResponse > {
135- await initialize ( ) ;
136- return proto . UnBlindOberonTokenResponse . deserializeBinary (
137- native . oberon_unblind_token ( request . serializeBinary ( ) )
138- ) ;
139- }
71+ static async createKey ( request : proto . CreateOberonKeyRequest ) : Promise < proto . CreateOberonKeyResponse > {
72+ await initialize ( ) ;
73+ return proto . CreateOberonKeyResponse . deserializeBinary ( native . oberon_create_key ( request . serializeBinary ( ) ) ) ;
74+ }
75+
76+ static async createToken ( request : proto . CreateOberonTokenRequest ) : Promise < proto . CreateOberonTokenResponse > {
77+ await initialize ( ) ;
78+ return proto . CreateOberonTokenResponse . deserializeBinary ( native . oberon_create_token ( request . serializeBinary ( ) ) ) ;
79+ }
80+
81+ static async createProof ( request : proto . CreateOberonProofRequest ) : Promise < proto . CreateOberonProofResponse > {
82+ await initialize ( ) ;
83+ return proto . CreateOberonProofResponse . deserializeBinary ( native . oberon_create_proof ( request . serializeBinary ( ) ) ) ;
84+ }
85+
86+ static async verifyProof ( request : proto . VerifyOberonProofRequest ) : Promise < proto . VerifyOberonProofResponse > {
87+ await initialize ( ) ;
88+ return proto . VerifyOberonProofResponse . deserializeBinary ( native . oberon_verify_proof ( request . serializeBinary ( ) ) ) ;
89+ }
90+
91+ static async blindToken ( request : proto . BlindOberonTokenRequest ) : Promise < proto . BlindOberonTokenResponse > {
92+ await initialize ( ) ;
93+ return proto . BlindOberonTokenResponse . deserializeBinary ( native . oberon_blind_token ( request . serializeBinary ( ) ) ) ;
94+ }
95+
96+ static async unblindToken ( request : proto . UnBlindOberonTokenRequest ) : Promise < proto . UnBlindOberonTokenResponse > {
97+ await initialize ( ) ;
98+ return proto . UnBlindOberonTokenResponse . deserializeBinary ( native . oberon_unblind_token ( request . serializeBinary ( ) ) ) ;
99+ }
140100}
141101
142102export class Hashing {
143- static blake3Hash (
144- request : proto . Blake3HashRequest
145- ) : Promise < proto . Blake3HashResponse > {
146- return Promise . resolve (
147- proto . Blake3HashResponse . deserializeBinary (
148- native . blake3_hash ( request . serializeBinary ( ) )
149- )
150- ) ;
151- }
152- static blake3KeyedHash (
153- request : proto . Blake3KeyedHashRequest
154- ) : Promise < proto . Blake3KeyedHashResponse > {
155- return Promise . resolve (
156- proto . Blake3KeyedHashResponse . deserializeBinary (
157- native . blake3_keyed_hash ( request . serializeBinary ( ) )
158- )
159- ) ;
160- }
161- static blake3DeriveKey (
162- request : proto . Blake3DeriveKeyRequest
163- ) : Promise < proto . Blake3DeriveKeyResponse > {
164- return Promise . resolve (
165- proto . Blake3DeriveKeyResponse . deserializeBinary (
166- native . blake3_derive_key ( request . serializeBinary ( ) )
167- )
168- ) ;
169- }
170- static sha256Hash (
171- request : proto . SHA256HashRequest
172- ) : Promise < proto . SHA256HashResponse > {
173- return Promise . resolve (
174- proto . SHA256HashResponse . deserializeBinary (
175- native . sha256_hash ( request . serializeBinary ( ) )
176- )
177- ) ;
178- }
103+ static async blake3Hash ( request : proto . Blake3HashRequest ) : Promise < proto . Blake3HashResponse > {
104+ await initialize ( ) ;
105+ return proto . Blake3HashResponse . deserializeBinary ( native . blake3_hash ( request . serializeBinary ( ) ) ) ;
106+ }
107+
108+ static async blake3KeyedHash ( request : proto . Blake3KeyedHashRequest ) : Promise < proto . Blake3KeyedHashResponse > {
109+ await initialize ( ) ;
110+ return proto . Blake3KeyedHashResponse . deserializeBinary ( native . blake3_keyed_hash ( request . serializeBinary ( ) ) ) ;
111+ }
112+
113+ static async blake3DeriveKey ( request : proto . Blake3DeriveKeyRequest ) : Promise < proto . Blake3DeriveKeyResponse > {
114+ await initialize ( ) ;
115+ return proto . Blake3DeriveKeyResponse . deserializeBinary ( native . blake3_derive_key ( request . serializeBinary ( ) ) ) ;
116+ }
117+
118+ static async sha256Hash ( request : proto . SHA256HashRequest ) : Promise < proto . SHA256HashResponse > {
119+ await initialize ( ) ;
120+ return proto . SHA256HashResponse . deserializeBinary ( native . sha256_hash ( request . serializeBinary ( ) ) ) ;
121+ }
179122}
0 commit comments