Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Bech32-encoded state controller and governor addresses #1044

Merged
merged 9 commits into from
Sep 22, 2022
72 changes: 50 additions & 22 deletions bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ See <code>IVerifierOptions</code>.</p>
## Members

<dl>
<dt><a href="#KeyType">KeyType</a></dt>
<dd></dd>
<dt><a href="#MethodRelationship">MethodRelationship</a></dt>
<dd></dd>
<dt><a href="#StateMetadataEncoding">StateMetadataEncoding</a></dt>
<dd></dd>
<dt><a href="#StatusCheck">StatusCheck</a></dt>
<dd><p>Controls validation behaviour when checking whether or not a credential has been revoked by its
<a href="https://www.w3.org/TR/vc-data-model/#status"><code>credentialStatus</code></a>.</p>
Expand Down Expand Up @@ -144,12 +150,6 @@ This variant is the default used if no other variant is specified when construct
<dt><a href="#FirstError">FirstError</a></dt>
<dd><p>Return after the first error occurs.</p>
</dd>
<dt><a href="#KeyType">KeyType</a></dt>
<dd></dd>
<dt><a href="#MethodRelationship">MethodRelationship</a></dt>
<dd></dd>
<dt><a href="#StateMetadataEncoding">StateMetadataEncoding</a></dt>
<dd></dd>
</dl>

## Functions
Expand Down Expand Up @@ -1988,14 +1988,16 @@ Deserializes an instance from a JSON object.
* [.setMetadataUpdated(timestamp)](#IotaDocument+setMetadataUpdated)
* [.metadataDeactivated()](#IotaDocument+metadataDeactivated) ⇒ <code>boolean</code> \| <code>undefined</code>
* [.setMetadataDeactivated(deactivated)](#IotaDocument+setMetadataDeactivated)
* [.metadataStateControllerAddress()](#IotaDocument+metadataStateControllerAddress) ⇒ <code>string</code> \| <code>undefined</code>
* [.metadataGovernorAddress()](#IotaDocument+metadataGovernorAddress) ⇒ <code>string</code> \| <code>undefined</code>
* [.setMetadataPropertyUnchecked(key, value)](#IotaDocument+setMetadataPropertyUnchecked)
* [.revokeCredentials(serviceQuery, indices)](#IotaDocument+revokeCredentials)
* [.unrevokeCredentials(serviceQuery, indices)](#IotaDocument+unrevokeCredentials)
* [.toJSON()](#IotaDocument+toJSON) ⇒ <code>any</code>
* [.clone()](#IotaDocument+clone) ⇒ [<code>IotaDocument</code>](#IotaDocument)
* _static_
* [.newWithId(id)](#IotaDocument.newWithId) ⇒ [<code>IotaDocument</code>](#IotaDocument)
* [.unpack(did, stateMetadata, allowEmpty)](#IotaDocument.unpack) ⇒ [<code>IotaDocument</code>](#IotaDocument)
* [.unpackFromOutput(did, aliasDto, allowEmpty)](#IotaDocument.unpackFromOutput) ⇒ [<code>IotaDocument</code>](#IotaDocument)
* [.unpackFromBlock(network, block)](#IotaDocument.unpackFromBlock) ⇒ [<code>Array.&lt;IotaDocument&gt;</code>](#IotaDocument)
* [.fromJSON(json)](#IotaDocument.fromJSON) ⇒ [<code>IotaDocument</code>](#IotaDocument)

Expand Down Expand Up @@ -2323,6 +2325,18 @@ Sets the deactivated status of the DID document.
| --- | --- |
| deactivated | <code>boolean</code> \| <code>undefined</code> |

<a name="IotaDocument+metadataStateControllerAddress"></a>

### iotaDocument.metadataStateControllerAddress() ⇒ <code>string</code> \| <code>undefined</code>
Returns a copy of the Bech32-encoded state controller address, if present.

**Kind**: instance method of [<code>IotaDocument</code>](#IotaDocument)
<a name="IotaDocument+metadataGovernorAddress"></a>

### iotaDocument.metadataGovernorAddress() ⇒ <code>string</code> \| <code>undefined</code>
Returns a copy of the Bech32-encoded governor address, if present.

**Kind**: instance method of [<code>IotaDocument</code>](#IotaDocument)
<a name="IotaDocument+setMetadataPropertyUnchecked"></a>

### iotaDocument.setMetadataPropertyUnchecked(key, value)
Expand Down Expand Up @@ -2385,9 +2399,9 @@ Constructs an empty DID Document with the given identifier.
| --- | --- |
| id | [<code>IotaDID</code>](#IotaDID) |

<a name="IotaDocument.unpack"></a>
<a name="IotaDocument.unpackFromOutput"></a>

### IotaDocument.unpack(did, stateMetadata, allowEmpty) ⇒ [<code>IotaDocument</code>](#IotaDocument)
### IotaDocument.unpackFromOutput(did, aliasDto, allowEmpty) ⇒ [<code>IotaDocument</code>](#IotaDocument)
Deserializes the document from the state metadata bytes of an Alias Output.

If `allowEmpty` is true, this will return an empty DID document marked as `deactivated`
Expand All @@ -2402,7 +2416,7 @@ encoded in the `AliasId` alone.
| Param | Type |
| --- | --- |
| did | [<code>IotaDID</code>](#IotaDID) |
| stateMetadata | <code>Uint8Array</code> |
| aliasDto | <code>any</code> |
| allowEmpty | <code>boolean</code> |

<a name="IotaDocument.unpackFromBlock"></a>
Expand Down Expand Up @@ -2443,6 +2457,8 @@ Additional attributes related to an IOTA DID Document.
* [.created()](#IotaDocumentMetadata+created) ⇒ [<code>Timestamp</code>](#Timestamp) \| <code>undefined</code>
* [.updated()](#IotaDocumentMetadata+updated) ⇒ [<code>Timestamp</code>](#Timestamp) \| <code>undefined</code>
* [.deactivated()](#IotaDocumentMetadata+deactivated) ⇒ <code>boolean</code> \| <code>undefined</code>
* [.stateControllerAddress()](#IotaDocumentMetadata+stateControllerAddress) ⇒ <code>string</code> \| <code>undefined</code>
* [.governorAddress()](#IotaDocumentMetadata+governorAddress) ⇒ <code>string</code> \| <code>undefined</code>
* [.properties()](#IotaDocumentMetadata+properties) ⇒ <code>Map.&lt;string, any&gt;</code>
* [.toJSON()](#IotaDocumentMetadata+toJSON) ⇒ <code>any</code>
* [.clone()](#IotaDocumentMetadata+clone) ⇒ [<code>IotaDocumentMetadata</code>](#IotaDocumentMetadata)
Expand All @@ -2466,6 +2482,18 @@ Returns a copy of the timestamp of the last DID document update.
### iotaDocumentMetadata.deactivated() ⇒ <code>boolean</code> \| <code>undefined</code>
Returns a copy of the deactivated status of the DID document.

**Kind**: instance method of [<code>IotaDocumentMetadata</code>](#IotaDocumentMetadata)
<a name="IotaDocumentMetadata+stateControllerAddress"></a>

### iotaDocumentMetadata.stateControllerAddress() ⇒ <code>string</code> \| <code>undefined</code>
Returns a copy of the Bech32-encoded state controller address, if present.

**Kind**: instance method of [<code>IotaDocumentMetadata</code>](#IotaDocumentMetadata)
<a name="IotaDocumentMetadata+governorAddress"></a>

### iotaDocumentMetadata.governorAddress() ⇒ <code>string</code> \| <code>undefined</code>
Returns a copy of the Bech32-encoded governor address, if present.

**Kind**: instance method of [<code>IotaDocumentMetadata</code>](#IotaDocumentMetadata)
<a name="IotaDocumentMetadata+properties"></a>

Expand Down Expand Up @@ -4007,6 +4035,18 @@ This is possible because Ed25519 is birationally equivalent to Curve25519 used b
| --- | --- |
| publicKey | <code>Uint8Array</code> |

<a name="KeyType"></a>

## KeyType
**Kind**: global variable
<a name="MethodRelationship"></a>

## MethodRelationship
**Kind**: global variable
<a name="StateMetadataEncoding"></a>

## StateMetadataEncoding
**Kind**: global variable
<a name="StatusCheck"></a>

## StatusCheck
Expand Down Expand Up @@ -4084,18 +4124,6 @@ Return all errors that occur during validation.
## FirstError
Return after the first error occurs.

**Kind**: global variable
<a name="KeyType"></a>

## KeyType
**Kind**: global variable
<a name="MethodRelationship"></a>

## MethodRelationship
**Kind**: global variable
<a name="StateMetadataEncoding"></a>

## StateMetadataEncoding
**Kind**: global variable
<a name="start"></a>

Expand Down
12 changes: 12 additions & 0 deletions bindings/wasm/src/iota/iota_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,18 @@ impl WasmIotaDocument {
self.0.metadata.deactivated = deactivated;
}

/// Returns a copy of the Bech32-encoded state controller address, if present.
#[wasm_bindgen(js_name = metadataStateControllerAddress)]
pub fn metadata_state_controller_address(&self) -> Option<String> {
self.0.metadata.state_controller_address.clone()
}

/// Returns a copy of the Bech32-encoded governor address, if present.
#[wasm_bindgen(js_name = metadataGovernorAddress)]
pub fn metadata_governor_address(&self) -> Option<String> {
self.0.metadata.governor_address.clone()
}

/// Sets a custom property in the document metadata.
/// If the value is set to `null`, the custom property will be removed.
#[wasm_bindgen(js_name = setMetadataPropertyUnchecked)]
Expand Down
12 changes: 12 additions & 0 deletions bindings/wasm/src/iota/iota_document_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ impl WasmIotaDocumentMetadata {
self.0.deactivated
}

/// Returns a copy of the Bech32-encoded state controller address, if present.
#[wasm_bindgen(js_name = stateControllerAddress)]
pub fn state_controller_address(&self) -> Option<String> {
self.0.state_controller_address.clone()
}

/// Returns a copy of the Bech32-encoded governor address, if present.
#[wasm_bindgen(js_name = governorAddress)]
pub fn governor_address(&self) -> Option<String> {
self.0.governor_address.clone()
}

/// Returns a copy of the custom metadata properties.
#[wasm_bindgen]
pub fn properties(&self) -> Result<MapStringAny> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"doc": {
"id": "did:iota:0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"id": "did:iota:0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"verificationMethod": [
{
"id": "did:iota:0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA#issuerKey",
"controller": "did:iota:0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"id": "did:iota:0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa#issuerKey",
"controller": "did:iota:0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"type": "Ed25519VerificationKey2018",
"publicKeyMultibase": "zFVen3X669xLzsi6N2V91DoiyzHzg1uAgqiT8jZ9nS96Z"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,37 @@
{
"@context": "https://www.w3.org/2018/credentials/v1",
"id": "https://example.org/credentials/3732",
"type": "VerifiablePresentation",
"verifiableCredential": [
{
"@context": "https://www.w3.org/2018/credentials/v1",
"id": "https://example.edu/credentials/3732",
"type": [
"VerifiableCredential",
"UniversityDegreeCredential"
],
"credentialSubject": {
"id": "did:foo:586Z7H2vpX9qNhN2T4e9Utugie3ogjbxzGaMtM3E6HR5",
"GPA": "4.0",
"degree": {
"name": "Bachelor of Science and Arts",
"type": "BachelorDegree"
},
"name": "Alice"
"@context": "https://www.w3.org/2018/credentials/v1",
"id": "https://example.org/credentials/3732",
"type": "VerifiablePresentation",
"verifiableCredential": {
"@context": "https://www.w3.org/2018/credentials/v1",
"id": "https://example.edu/credentials/3732",
"type": [
"VerifiableCredential",
"UniversityDegreeCredential"
],
"credentialSubject": {
"id": "did:foo:586Z7H2vpX9qNhN2T4e9Utugie3ogjbxzGaMtM3E6HR5",
"GPA": "4.0",
"degree": {
"name": "Bachelor of Science and Arts",
"type": "BachelorDegree"
},
"issuer": "did:iota:0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"issuanceDate": "2022-08-31T08:35:44Z",
"expirationDate": "2050-09-01T08:35:44Z",
"proof": {
"type": "JcsEd25519Signature2020",
"verificationMethod": "did:iota:0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA#issuerKey",
"signatureValue": "3d2aAPqjzaSQ2XbFtqLsauv2Ukdn4Hcevz2grNuJn4q4JbBmDHZpAvekVG12A3ZKRRTeKaBPguxXqcDaqujckWWz"
}
"name": "Alice"
},
{
"@context": "https://www.w3.org/2018/credentials/v1",
"id": "https://example.edu/credentials/3732",
"type": [
"VerifiableCredential",
"UniversityDegreeCredential"
],
"credentialSubject": {
"id": "did:foo:586Z7H2vpX9qNhN2T4e9Utugie3ogjbxzGaMtM3E6HR5",
"GPA": "4.0",
"degree": {
"name": "Bachelor of Science and Arts",
"type": "BachelorDegree"
},
"name": "Alice"
},
"issuer": "did:bar:Hyx62wPQGyvXCoihZq1BrbUjBRh2LuNxWiiqMkfAuSZr",
"issuanceDate": "2022-08-31T08:35:44Z",
"expirationDate": "2050-09-01T08:35:44Z",
"proof": {
"type": "JcsEd25519Signature2020",
"verificationMethod": "did:bar:Hyx62wPQGyvXCoihZq1BrbUjBRh2LuNxWiiqMkfAuSZr#root",
"signatureValue": "2iAYujqHLXP5csZzabdkfurpHaKT3Q8dnJDA4TL7pSJ7gjXLCb2tN7CF4ztKkCKmvY6VYG3pTuN1PeLGEFiQvuQr"
}
"issuer": "did:iota:0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"issuanceDate": "2022-08-31T08:35:44Z",
"expirationDate": "2050-09-01T08:35:44Z",
"proof": {
"type": "JcsEd25519Signature2020",
"verificationMethod": "did:iota:0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa#issuerKey",
"signatureValue": "2xoRHPUWRVavrBsymJCKhTUe9iYX8iEEZtPhaMjmFvVmjaybVUYXHJagw9kCFmDoPgeyvZjRVQatp2VYs1b8f2Ug"
}
],
"holder": "did:foo:586Z7H2vpX9qNhN2T4e9Utugie3ogjbxzGaMtM3E6HR5",
"proof": {
"type": "JcsEd25519Signature2020",
"verificationMethod": "did:foo:586Z7H2vpX9qNhN2T4e9Utugie3ogjbxzGaMtM3E6HR5#root",
"signatureValue": "3tVeoKjftrEAQvV3MgpKgiydRHU6i8mYVRnPc6C85upo1TDBEdN94gyW1RzbgPESaZCGeDa582BxAUHVE4rVjaAd",
"challenge": "475a7984-1bb5-4c4c-a56f-822bccd46441"
}
}
},
"holder": "did:foo:586Z7H2vpX9qNhN2T4e9Utugie3ogjbxzGaMtM3E6HR5",
"proof": {
"type": "JcsEd25519Signature2020",
"verificationMethod": "did:foo:586Z7H2vpX9qNhN2T4e9Utugie3ogjbxzGaMtM3E6HR5#root",
"signatureValue": "5xgWVFQ8J5rsYkkF2BLxzY6YDfdGoZXfT9R9rJPbq53MHc3QkLrpr49kY9aMtQQzEL53nBxJZMtihN2F5nZ44TeR",
"challenge": "475a7984-1bb5-4c4c-a56f-822bccd46441"
}
}
2 changes: 1 addition & 1 deletion identity_iota_core/src/did/iota_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl IotaDID {
///
/// Returns `Err` if the input does not conform to the [`IotaDID`] specification.
pub fn parse(input: impl AsRef<str>) -> Result<Self> {
CoreDID::parse(input).and_then(Self::try_from_core)
CoreDID::parse(input.as_ref().to_lowercase()).and_then(Self::try_from_core)
}

/// Converts a [`CoreDID`] to a [`IotaDID`].
Expand Down
Loading