Skip to content

Commit 533b7c6

Browse files
Implement JwkStorage (iotaledger#1116)
* Implement first `KeyStorage` version * Add `KeyStorage::exists` * Add `is_public` and `is_private` to `Jwk` * Implement `insert_jwk` * Improve error names * Expose `send-sync-storage` feature * Add license headers * Move write guard closer to use * Reexport storage in `identity_iota` * Rename `KeyStorage` to `JwkStorage` * Set sig alg at key gen/insert time * Start implementing `WasmJwkStorage` * Implement JwkStorage in Wasm * Add `KeyId` to `String` conversion * Bump to latest version * Add JOSE module in Wasm * Implement string enums in TS * Fix `JwkType` doc * Replace all occurences of paths * Format TS files * Return proper types from JWK type * Expose JWK params * Expose `EdCurve` and `EcCurve` * Expose the rest of `JwkStorage` in TS * Add jose index file * Implement MemStore as test * Remove test function * Document JWK * Add license headers, regenerate docs * Fix doc build * Rebuild API reference * Fmt wasm * Fix docs * Polish docs, names * Polish imports
1 parent 6624b56 commit 533b7c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2212
-49
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"identity_diff",
1111
"identity_document",
1212
"identity_iota",
13+
"identity_storage",
1314
"identity_iota_core",
1415
"identity_resolver",
1516
"identity_verification",

bindings/wasm/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ path = "../../identity_iota"
3636
default-features = false
3737
features = ["client", "revocation-bitmap", "resolver"]
3838

39+
[dependencies.identity_jose]
40+
version = "0.7.0-alpha.4"
41+
path = "../../identity_jose"
42+
default-features = false
43+
features = []
44+
3945
[dev-dependencies]
4046
rand = "0.8.5"
4147

bindings/wasm/build/replace_paths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function replace(tsconfig, dist) {
2626
let fileData = await fs.readFile(path.join(__dirname, `../${dist}/${file}`), "utf8");
2727
for (let key of keys) {
2828
let value = a[key][1] ?? a[key][0];
29-
fileData = fileData.replace(key, value);
29+
fileData = fileData.replaceAll(key, value);
3030
}
3131
await fs.writeFile(path.join(__dirname, `../${dist}/${file}`), fileData, "utf8");
3232
}

bindings/wasm/docs/api-reference.md

Lines changed: 226 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ is supported.</li>
4747
<dd><p>An extension interface that provides helper functions for publication
4848
and resolution of DID documents in Alias Outputs.</p>
4949
</dd>
50+
<dt><a href="#Jwk">Jwk</a></dt>
51+
<dd></dd>
52+
<dt><a href="#JwkGenOutput">JwkGenOutput</a></dt>
53+
<dd><p>The result of a key generation in <code>JwkStorage</code>.</p>
54+
</dd>
5055
<dt><a href="#KeyPair">KeyPair</a></dt>
5156
<dd></dd>
5257
<dt><a href="#LinkedDomainService">LinkedDomainService</a></dt>
@@ -109,8 +114,6 @@ See <code>IVerifierOptions</code>.</p>
109114
## Members
110115

111116
<dl>
112-
<dt><a href="#MethodRelationship">MethodRelationship</a></dt>
113-
<dd></dd>
114117
<dt><a href="#StatusCheck">StatusCheck</a></dt>
115118
<dd><p>Controls validation behaviour when checking whether or not a credential has been revoked by its
116119
<a href="https://www.w3.org/TR/vc-data-model/#status"><code>credentialStatus</code></a>.</p>
@@ -157,6 +160,8 @@ This variant is the default used if no other variant is specified when construct
157160
<dd></dd>
158161
<dt><a href="#KeyType">KeyType</a></dt>
159162
<dd></dd>
163+
<dt><a href="#MethodRelationship">MethodRelationship</a></dt>
164+
<dd></dd>
160165
</dl>
161166

162167
## Functions
@@ -2464,6 +2469,221 @@ Fetches the `IAliasOutput` associated with the given DID.
24642469
| client | <code>IIotaIdentityClient</code> |
24652470
| did | [<code>IotaDID</code>](#IotaDID) |
24662471

2472+
<a name="Jwk"></a>
2473+
2474+
## Jwk
2475+
**Kind**: global class
2476+
2477+
* [Jwk](#Jwk)
2478+
* [new Jwk(jwk)](#new_Jwk_new)
2479+
* _instance_
2480+
* [.kty()](#Jwk+kty) ⇒ <code>JwkType</code>
2481+
* [.use()](#Jwk+use) ⇒ <code>JwkUse</code> \| <code>undefined</code>
2482+
* [.keyOps()](#Jwk+keyOps) ⇒ <code>Array.&lt;JwkOperation&gt;</code>
2483+
* [.alg()](#Jwk+alg) ⇒ <code>JwsAlgorithm</code> \| <code>undefined</code>
2484+
* [.kid()](#Jwk+kid) ⇒ <code>string</code> \| <code>undefined</code>
2485+
* [.x5u()](#Jwk+x5u) ⇒ <code>string</code> \| <code>undefined</code>
2486+
* [.x5c()](#Jwk+x5c) ⇒ <code>Array.&lt;string&gt;</code>
2487+
* [.x5t()](#Jwk+x5t) ⇒ <code>string</code> \| <code>undefined</code>
2488+
* [.x5t256()](#Jwk+x5t256) ⇒ <code>string</code> \| <code>undefined</code>
2489+
* [.paramsEc()](#Jwk+paramsEc) ⇒ <code>JwkParamsEc</code> \| <code>undefined</code>
2490+
* [.paramsOkp()](#Jwk+paramsOkp) ⇒ <code>JwkParamsOkp</code> \| <code>undefined</code>
2491+
* [.paramsOct()](#Jwk+paramsOct) ⇒ <code>JwkParamsOct</code> \| <code>undefined</code>
2492+
* [.paramsRsa()](#Jwk+paramsRsa) ⇒ <code>JwkParamsRsa</code> \| <code>undefined</code>
2493+
* [.toPublic()](#Jwk+toPublic)[<code>Jwk</code>](#Jwk)
2494+
* [.isPublic()](#Jwk+isPublic) ⇒ <code>boolean</code>
2495+
* [.isPrivate()](#Jwk+isPrivate) ⇒ <code>boolean</code>
2496+
* [.toJSON()](#Jwk+toJSON) ⇒ <code>any</code>
2497+
* [.clone()](#Jwk+clone)[<code>Jwk</code>](#Jwk)
2498+
* _static_
2499+
* [.fromJSON(json)](#Jwk.fromJSON)[<code>Jwk</code>](#Jwk)
2500+
2501+
<a name="new_Jwk_new"></a>
2502+
2503+
### new Jwk(jwk)
2504+
2505+
| Param | Type |
2506+
| --- | --- |
2507+
| jwk | <code>IJwkParams</code> |
2508+
2509+
<a name="Jwk+kty"></a>
2510+
2511+
### jwk.kty() ⇒ <code>JwkType</code>
2512+
Returns the value for the key type parameter (kty).
2513+
2514+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2515+
<a name="Jwk+use"></a>
2516+
2517+
### jwk.use() ⇒ <code>JwkUse</code> \| <code>undefined</code>
2518+
Returns the value for the use property (use).
2519+
2520+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2521+
<a name="Jwk+keyOps"></a>
2522+
2523+
### jwk.keyOps() ⇒ <code>Array.&lt;JwkOperation&gt;</code>
2524+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2525+
<a name="Jwk+alg"></a>
2526+
2527+
### jwk.alg() ⇒ <code>JwsAlgorithm</code> \| <code>undefined</code>
2528+
Returns the value for the algorithm property (alg).
2529+
2530+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2531+
<a name="Jwk+kid"></a>
2532+
2533+
### jwk.kid() ⇒ <code>string</code> \| <code>undefined</code>
2534+
Returns the value of the key ID property (kid).
2535+
2536+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2537+
<a name="Jwk+x5u"></a>
2538+
2539+
### jwk.x5u() ⇒ <code>string</code> \| <code>undefined</code>
2540+
Returns the value of the X.509 URL property (x5u).
2541+
2542+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2543+
<a name="Jwk+x5c"></a>
2544+
2545+
### jwk.x5c() ⇒ <code>Array.&lt;string&gt;</code>
2546+
Returns the value of the X.509 certificate chain property (x5c).
2547+
2548+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2549+
<a name="Jwk+x5t"></a>
2550+
2551+
### jwk.x5t() ⇒ <code>string</code> \| <code>undefined</code>
2552+
Returns the value of the X.509 certificate SHA-1 thumbprint property (x5t).
2553+
2554+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2555+
<a name="Jwk+x5t256"></a>
2556+
2557+
### jwk.x5t256() ⇒ <code>string</code> \| <code>undefined</code>
2558+
Returns the value of the X.509 certificate SHA-256 thumbprint property (x5t#S256).
2559+
2560+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2561+
<a name="Jwk+paramsEc"></a>
2562+
2563+
### jwk.paramsEc() ⇒ <code>JwkParamsEc</code> \| <code>undefined</code>
2564+
If this JWK is of kty EC, returns those parameters.
2565+
2566+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2567+
<a name="Jwk+paramsOkp"></a>
2568+
2569+
### jwk.paramsOkp() ⇒ <code>JwkParamsOkp</code> \| <code>undefined</code>
2570+
If this JWK is of kty OKP, returns those parameters.
2571+
2572+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2573+
<a name="Jwk+paramsOct"></a>
2574+
2575+
### jwk.paramsOct() ⇒ <code>JwkParamsOct</code> \| <code>undefined</code>
2576+
If this JWK is of kty OCT, returns those parameters.
2577+
2578+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2579+
<a name="Jwk+paramsRsa"></a>
2580+
2581+
### jwk.paramsRsa() ⇒ <code>JwkParamsRsa</code> \| <code>undefined</code>
2582+
If this JWK is of kty RSA, returns those parameters.
2583+
2584+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2585+
<a name="Jwk+toPublic"></a>
2586+
2587+
### jwk.toPublic() ⇒ [<code>Jwk</code>](#Jwk)
2588+
Returns a clone of the Jwk with _all_ private key components unset.
2589+
2590+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2591+
<a name="Jwk+isPublic"></a>
2592+
2593+
### jwk.isPublic() ⇒ <code>boolean</code>
2594+
Returns `true` if _all_ private key components of the key are unset, `false` otherwise.
2595+
2596+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2597+
<a name="Jwk+isPrivate"></a>
2598+
2599+
### jwk.isPrivate() ⇒ <code>boolean</code>
2600+
Returns `true` if _all_ private key components of the key are set, `false` otherwise.
2601+
2602+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2603+
<a name="Jwk+toJSON"></a>
2604+
2605+
### jwk.toJSON() ⇒ <code>any</code>
2606+
Serializes this to a JSON object.
2607+
2608+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2609+
<a name="Jwk+clone"></a>
2610+
2611+
### jwk.clone() ⇒ [<code>Jwk</code>](#Jwk)
2612+
Deep clones the object.
2613+
2614+
**Kind**: instance method of [<code>Jwk</code>](#Jwk)
2615+
<a name="Jwk.fromJSON"></a>
2616+
2617+
### Jwk.fromJSON(json) ⇒ [<code>Jwk</code>](#Jwk)
2618+
Deserializes an instance from a JSON object.
2619+
2620+
**Kind**: static method of [<code>Jwk</code>](#Jwk)
2621+
2622+
| Param | Type |
2623+
| --- | --- |
2624+
| json | <code>any</code> |
2625+
2626+
<a name="JwkGenOutput"></a>
2627+
2628+
## JwkGenOutput
2629+
The result of a key generation in `JwkStorage`.
2630+
2631+
**Kind**: global class
2632+
2633+
* [JwkGenOutput](#JwkGenOutput)
2634+
* [new JwkGenOutput(key_id, jwk)](#new_JwkGenOutput_new)
2635+
* _instance_
2636+
* [.jwk()](#JwkGenOutput+jwk)[<code>Jwk</code>](#Jwk)
2637+
* [.keyId()](#JwkGenOutput+keyId) ⇒ <code>string</code>
2638+
* [.toJSON()](#JwkGenOutput+toJSON) ⇒ <code>any</code>
2639+
* [.clone()](#JwkGenOutput+clone)[<code>JwkGenOutput</code>](#JwkGenOutput)
2640+
* _static_
2641+
* [.fromJSON(json)](#JwkGenOutput.fromJSON)[<code>JwkGenOutput</code>](#JwkGenOutput)
2642+
2643+
<a name="new_JwkGenOutput_new"></a>
2644+
2645+
### new JwkGenOutput(key_id, jwk)
2646+
2647+
| Param | Type |
2648+
| --- | --- |
2649+
| key_id | <code>string</code> |
2650+
| jwk | [<code>Jwk</code>](#Jwk) |
2651+
2652+
<a name="JwkGenOutput+jwk"></a>
2653+
2654+
### jwkGenOutput.jwk() ⇒ [<code>Jwk</code>](#Jwk)
2655+
Returns the generated public JWK.
2656+
2657+
**Kind**: instance method of [<code>JwkGenOutput</code>](#JwkGenOutput)
2658+
<a name="JwkGenOutput+keyId"></a>
2659+
2660+
### jwkGenOutput.keyId() ⇒ <code>string</code>
2661+
Returns the key id of the generated jwk.
2662+
2663+
**Kind**: instance method of [<code>JwkGenOutput</code>](#JwkGenOutput)
2664+
<a name="JwkGenOutput+toJSON"></a>
2665+
2666+
### jwkGenOutput.toJSON() ⇒ <code>any</code>
2667+
Serializes this to a JSON object.
2668+
2669+
**Kind**: instance method of [<code>JwkGenOutput</code>](#JwkGenOutput)
2670+
<a name="JwkGenOutput+clone"></a>
2671+
2672+
### jwkGenOutput.clone() ⇒ [<code>JwkGenOutput</code>](#JwkGenOutput)
2673+
Deep clones the object.
2674+
2675+
**Kind**: instance method of [<code>JwkGenOutput</code>](#JwkGenOutput)
2676+
<a name="JwkGenOutput.fromJSON"></a>
2677+
2678+
### JwkGenOutput.fromJSON(json) ⇒ [<code>JwkGenOutput</code>](#JwkGenOutput)
2679+
Deserializes an instance from a JSON object.
2680+
2681+
**Kind**: static method of [<code>JwkGenOutput</code>](#JwkGenOutput)
2682+
2683+
| Param | Type |
2684+
| --- | --- |
2685+
| json | <code>any</code> |
2686+
24672687
<a name="KeyPair"></a>
24682688

24692689
## KeyPair
@@ -3949,10 +4169,6 @@ This is possible because Ed25519 is birationally equivalent to Curve25519 used b
39494169
| --- | --- |
39504170
| publicKey | <code>Uint8Array</code> |
39514171

3952-
<a name="MethodRelationship"></a>
3953-
3954-
## MethodRelationship
3955-
**Kind**: global variable
39564172
<a name="StatusCheck"></a>
39574173

39584174
## StatusCheck
@@ -4039,6 +4255,10 @@ Return after the first error occurs.
40394255

40404256
## KeyType
40414257
**Kind**: global variable
4258+
<a name="MethodRelationship"></a>
4259+
4260+
## MethodRelationship
4261+
**Kind**: global variable
40424262
<a name="start"></a>
40434263

40444264
## start()

bindings/wasm/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33

44
import "./append_functions";
55
export * from "./iota_identity_client";
6+
export * from "./jose/index";
67

78
export * from "~identity_wasm";

bindings/wasm/lib/jose/ec_curve.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** Supported Elliptic Curves.
2+
*
3+
* [More Info](https://www.iana.org/assignments/jose/jose.xhtml#web-key-elliptic-curve) */
4+
export const enum EcCurve {
5+
/** P-256 Curve. */
6+
P256,
7+
/** P-384 Curve. */
8+
P384,
9+
/** P-521 Curve. */
10+
P521,
11+
/** SECG secp256k1 curve. */
12+
Secp256K1,
13+
}

bindings/wasm/lib/jose/ed_curve.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** Supported Elliptic Curves.
2+
*
3+
* [More Info](https://www.iana.org/assignments/jose/jose.xhtml#web-key-elliptic-curve) */
4+
export const enum EdCurve {
5+
/** Ed25519 signature algorithm key pairs. */
6+
Ed25519 = "Ed25519",
7+
/** Ed448 signature algorithm key pairs. */
8+
Ed448 = "Ed448",
9+
}

bindings/wasm/lib/jose/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export * from "./ec_curve";
2+
export * from "./ed_curve";
3+
export * from "./jwk_operation";
4+
export * from "./jwk_type";
5+
export * from "./jwk_use";
6+
export * from "./jws_algorithm";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** Supported algorithms for the JSON Web Key `key_ops` property.
2+
*
3+
* [More Info](https://www.iana.org/assignments/jose/jose.xhtml#web-key-operations) */
4+
export const enum JwkOperation {
5+
/** Compute digital signature or MAC. */
6+
Sign = "sign",
7+
/** Verify digital signature or MAC. */
8+
Verify = "verify",
9+
/** Encrypt content. */
10+
Encrypt = "encrypt",
11+
/** Decrypt content and validate decryption, if applicable. */
12+
Decrypt = "decrypt",
13+
/** Encrypt key. */
14+
WrapKey = "wrapKey",
15+
/** Decrypt key and validate decryption, if applicable. */
16+
UnwrapKey = "unwrapKey",
17+
/** Derive key. */
18+
DeriveKey = "deriveKey",
19+
/** Derive bits not to be used as a key. */
20+
DeriveBits = "deriveBits",
21+
}

bindings/wasm/lib/jose/jwk_type.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** Supported types for the JSON Web Key `kty` property.
2+
*
3+
* [More Info](https://www.iana.org/assignments/jose/jose.xhtml#web-key-types) */
4+
export const enum JwkType {
5+
/** Elliptic Curve. */
6+
Ec = "EC",
7+
/** RSA. */
8+
Rsa = "RSA",
9+
/** Octet sequence. */
10+
Oct = "oct",
11+
/** Octet string key pairs. */
12+
Okp = "OKP",
13+
}

0 commit comments

Comments
 (0)