Class: IotaDocument
identity_wasm.IotaDocument
A DID Document adhering to the IOTA DID method specification.
Note: All methods that involve reading from this class may potentially raise an error if the object is being concurrently modified.
Table of contents
Constructors
Methods
- toJSON
- toString
- newWithId
- id
- controller
- setController
- alsoKnownAs
- setAlsoKnownAs
- properties
- setPropertyUnchecked
- service
- insertService
- removeService
- resolveService
- methods
- insertMethod
- removeMethod
- resolveMethod
- attachMethodRelationship
- detachMethodRelationship
- verifyJws
- pack
- packWithEncoding
- unpackFromOutput
- unpackFromBlock
- metadata
- metadataCreated
- setMetadataCreated
- metadataUpdated
- setMetadataUpdated
- metadataDeactivated
- setMetadataDeactivated
- metadataStateControllerAddress
- metadataGovernorAddress
- setMetadataPropertyUnchecked
- revokeCredentials
- unrevokeCredentials
- clone
- _shallowCloneInternal
- _strongCountInternal
- fromJSON
- toCoreDocument
- generateMethod
- purgeMethod
- createJwt
- createJws
- createCredentialJwt
- createPresentationJwt
Constructors
constructor
• new IotaDocument(network)
Constructs an empty IOTA DID Document with a placeholder identifier
for the given network.
Parameters
| Name | Type |
|---|---|
network | string |
Methods
toJSON
▸ toJSON(): Object
- Return copy of self without private attributes.
Returns
Object
▸ toJSON(): any
Serializes to a plain JS representation.
Returns
any
toString
▸ toString(): string
Return stringified version of self.
Returns
string
newWithId
▸ Static newWithId(id): IotaDocument
Constructs an empty DID Document with the given identifier.
Parameters
| Name | Type |
|---|---|
id | IotaDID |
Returns
id
▸ id(): IotaDID
Returns a copy of the DID Document id.
Returns
controller
▸ controller(): IotaDID[]
Returns a copy of the list of document controllers.
NOTE: controllers are determined by the state_controller unlock condition of the output
during resolution and are omitted when publishing.
Returns
IotaDID[]
setController
▸ setController(controller): void
Sets the controllers of the document.
Note: Duplicates will be ignored.
Use null to remove all controllers.
Parameters
| Name | Type |
|---|---|
controller | null | IotaDID[] |
Returns
void
alsoKnownAs
▸ alsoKnownAs(): string[]
Returns a copy of the document's alsoKnownAs set.
Returns
string[]
setAlsoKnownAs
▸ setAlsoKnownAs(urls): void
Sets the alsoKnownAs property in the DID document.
Parameters
| Name | Type |
|---|---|
urls | null | string | string[] |
Returns
void
properties
▸ properties(): Map\<string, any>
Returns a copy of the custom DID Document properties.
Returns
Map\<string, any>
setPropertyUnchecked
▸ setPropertyUnchecked(key, value): void
Sets a custom property in the DID Document.
If the value is set to null, the custom property will be removed.
WARNING
This method can overwrite existing properties like id and result in an invalid document.
Parameters
| Name | Type |
|---|---|
key | string |
value | any |
Returns
void
service
▸ service(): Service[]
Return a set of all Service in the document.
Returns
Service[]
insertService
▸ insertService(service): void
Add a new Service to the document.
Returns true if the service was added.
Parameters
| Name | Type |
|---|---|
service | Service |
Returns
void
removeService
▸ removeService(did): undefined | Service
Remove a Service identified by the given DIDUrl from the document.
Returns true if a service was removed.
Parameters
| Name | Type |
|---|---|
did | DIDUrl |
Returns
undefined | Service
resolveService
▸ resolveService(query): undefined | Service
Returns the first Service with an id property matching the provided query,
if present.
Parameters
| Name | Type |
|---|---|
query | string | DIDUrl |
Returns
undefined | Service
methods
▸ methods(scope?): VerificationMethod[]
Returns a list of all VerificationMethod in the DID Document,
whose verification relationship matches scope.
If scope is not set, a list over the embedded methods is returned.
Parameters
| Name | Type |
|---|---|
scope? | null | MethodScope |
Returns
insertMethod
▸ insertMethod(method, scope): void
Adds a new method to the document in the given scope.
Parameters
| Name | Type |
|---|---|
method | VerificationMethod |
scope | MethodScope |
Returns
void
removeMethod
▸ removeMethod(did): undefined | VerificationMethod
Removes all references to the specified Verification Method.
Parameters
| Name | Type |
|---|---|
did | DIDUrl |
Returns
undefined | VerificationMethod
resolveMethod
▸ resolveMethod(query, scope?): undefined | VerificationMethod
Returns a copy of the first verification method with an id property
matching the provided query and the verification relationship
specified by scope, if present.
Parameters
| Name | Type |
|---|---|
query | string | DIDUrl |
scope? | null | MethodScope |
Returns
undefined | VerificationMethod
attachMethodRelationship
▸ attachMethodRelationship(didUrl, relationship): boolean
Attaches the relationship to the given method, if the method exists.
Note: The method needs to be in the set of verification methods, so it cannot be an embedded one.
Parameters
| Name | Type |
|---|---|
didUrl | DIDUrl |
relationship | MethodRelationship |
Returns
boolean
detachMethodRelationship
▸ detachMethodRelationship(didUrl, relationship): boolean
Detaches the given relationship from the given method, if the method exists.
Parameters
| Name | Type |
|---|---|
didUrl | DIDUrl |
relationship | MethodRelationship |
Returns
boolean
verifyJws
▸ verifyJws(jws, options, signatureVerifier?, detachedPayload?): DecodedJws
Decodes and verifies the provided JWS according to the passed options and signatureVerifier.
If a signatureVerifier is provided it will be used when
verifying decoded JWS signatures, otherwise a default verifier capable of handling the EdDSA, ES256, ES256K
algorithms will be used.
Regardless of which options are passed the following conditions must be met in order for a verification attempt to take place.
- The JWS must be encoded according to the JWS compact serialization.
- The
kidvalue in the protected header must be an identifier of a verification method in this DID document.
Parameters
| Name | Type |
|---|---|
jws | Jws |
options | JwsVerificationOptions |
signatureVerifier? | null | IJwsVerifier |
detachedPayload? | null | string |
Returns
pack
▸ pack(): Uint8Array
Serializes the document for inclusion in an Alias Output's state metadata with the default StateMetadataEncoding.
Returns
Uint8Array
packWithEncoding
▸ packWithEncoding(encoding): Uint8Array
Serializes the document for inclusion in an Alias Output's state metadata.
Parameters
| Name | Type |
|---|---|
encoding | Json |
Returns
Uint8Array
unpackFromOutput
▸ Static unpackFromOutput(did, aliasOutput, allowEmpty): IotaDocument
Deserializes the document from an Alias Output.
If allowEmpty is true, this will return an empty DID document marked as deactivated
if stateMetadata is empty.
The tokenSupply must be equal to the token supply of the network the DID is associated with.
NOTE: did is required since it is omitted from the serialized DID Document and
cannot be inferred from the state metadata. It also indicates the network, which is not
encoded in the AliasId alone.
Parameters
| Name | Type |
|---|---|
did | IotaDID |
aliasOutput | AliasOutputBuilderParams |
allowEmpty | boolean |
Returns
unpackFromBlock
▸ Static unpackFromBlock(network, block): IotaDocument[]
Returns all DID documents of the Alias Outputs contained in the block's transaction payload outputs, if any.
Errors if any Alias Output does not contain a valid or empty DID Document.
Parameters
| Name | Type |
|---|---|
network | string |
block | Block |
Returns
metadata
▸ metadata(): IotaDocumentMetadata
Returns a copy of the metadata associated with this document.
NOTE: Copies all the metadata. See also metadataCreated, metadataUpdated,
metadataPreviousMessageId, metadataProof if only a subset of the metadata required.
Returns
metadataCreated
▸ metadataCreated(): undefined | Timestamp
Returns a copy of the timestamp of when the DID document was created.
Returns
undefined | Timestamp
setMetadataCreated
▸ setMetadataCreated(timestamp): void
Sets the timestamp of when the DID document was created.
Parameters
| Name | Type |
|---|---|
timestamp | undefined | Timestamp |
Returns
void
metadataUpdated
▸ metadataUpdated(): undefined | Timestamp
Returns a copy of the timestamp of the last DID document update.
Returns
undefined | Timestamp
setMetadataUpdated
▸ setMetadataUpdated(timestamp): void
Sets the timestamp of the last DID document update.
Parameters
| Name | Type |
|---|---|
timestamp | undefined | Timestamp |
Returns
void
metadataDeactivated
▸ metadataDeactivated(): undefined | boolean
Returns a copy of the deactivated status of the DID document.
Returns
undefined | boolean
setMetadataDeactivated
▸ setMetadataDeactivated(deactivated?): void
Sets the deactivated status of the DID document.
Parameters
| Name | Type |
|---|---|
deactivated? | null | boolean |
Returns
void
metadataStateControllerAddress
▸ metadataStateControllerAddress(): undefined | string
Returns a copy of the Bech32-encoded state controller address, if present.
Returns
undefined | string
metadataGovernorAddress
▸ metadataGovernorAddress(): undefined | string
Returns a copy of the Bech32-encoded governor address, if present.
Returns
undefined | string
setMetadataPropertyUnchecked
▸ setMetadataPropertyUnchecked(key, value): void
Sets a custom property in the document metadata.
If the value is set to null, the custom property will be removed.
Parameters
| Name | Type |
|---|---|
key | string |
value | any |
Returns
void
revokeCredentials
▸ revokeCredentials(serviceQuery, indices): void
If the document has a RevocationBitmap service identified by serviceQuery,
revoke all specified indices.
Parameters
| Name | Type |
|---|---|
serviceQuery | string | DIDUrl |
indices | number | number[] |
Returns
void
unrevokeCredentials
▸ unrevokeCredentials(serviceQuery, indices): void
If the document has a RevocationBitmap service identified by serviceQuery,
unrevoke all specified indices.
Parameters
| Name | Type |
|---|---|
serviceQuery | string | DIDUrl |
indices | number | number[] |
Returns
void
clone
▸ clone(): IotaDocument
Returns a deep clone of the IotaDocument.
Returns
_shallowCloneInternal
▸ _shallowCloneInternal(): IotaDocument
Warning
This is for internal use only. Do not rely on or call this method.
Returns
_strongCountInternal
▸ _strongCountInternal(): number
Warning
This is for internal use only. Do not rely on or call this method.
Returns
number
fromJSON
▸ Static fromJSON(json): IotaDocument
Deserializes an instance from a plain JS representation.
Parameters
| Name | Type |
|---|---|
json | any |
Returns
toCoreDocument
▸ toCoreDocument(): CoreDocument
Transforms the IotaDocument to its CoreDocument representation.
Returns
generateMethod
▸ generateMethod(storage, keyType, alg, fragment, scope): Promise\<string>
Generate new key material in the given storage and insert a new verification method with the corresponding
public key material into the DID document.
- If no fragment is given the
kidof the generated JWK is used, if it is set, otherwise an error is returned. - The
keyTypemust be compatible with the givenstorage.Storages are expected to export key type constants for that use case.
The fragment of the generated method is returned.
Parameters
| Name | Type |
|---|---|
storage | Storage |
keyType | string |
alg | JwsAlgorithm |
fragment | undefined | null | string |
scope | MethodScope |
Returns
Promise\<string>
purgeMethod
▸ purgeMethod(storage, id): Promise\<void>
Remove the method identified by the given fragment from the document and delete the corresponding key material in
the given storage.
Parameters
| Name | Type |
|---|---|
storage | Storage |
id | DIDUrl |
Returns
Promise\<void>
createJwt
▸ createJwt(storage, fragment, payload, options): Promise\<Jws>
Sign the payload according to options with the storage backed private key corresponding to the public key
material in the verification method identified by the given `fragment.
Upon success a string representing a JWS encoded according to the Compact JWS Serialization format is returned. See RFC7515 section 3.1.
@deprecated Use createJws() instead.
Parameters
| Name | Type |
|---|---|
storage | Storage |
fragment | string |
payload | string |
options | JwsSignatureOptions |
Returns
Promise\<Jws>
createJws
▸ createJws(storage, fragment, payload, options): Promise\<Jws>
Sign the payload according to options with the storage backed private key corresponding to the public key
material in the verification method identified by the given `fragment.
Upon success a string representing a JWS encoded according to the Compact JWS Serialization format is returned. See RFC7515 section 3.1.
Parameters
| Name | Type |
|---|---|
storage | Storage |
fragment | string |
payload | string |
options | JwsSignatureOptions |
Returns
Promise\<Jws>
createCredentialJwt
▸ createCredentialJwt(storage, fragment, credential, options, custom_claims?): Promise\<Jwt>
Produces a JWS where the payload is produced from the given credential
in accordance with VC Data Model v1.1.
Unless the kid is explicitly set in the options, the kid in the protected header is the id
of the method identified by fragment and the JWS signature will be produced by the corresponding
private key backed by the storage in accordance with the passed options.
The custom_claims can be used to set additional claims on the resulting JWT.
Parameters
| Name | Type |
|---|---|
storage | Storage |
fragment | string |
credential | Credential |
options | JwsSignatureOptions |
custom_claims? | null | Record\<string, any> |
Returns
Promise\<Jwt>
createPresentationJwt
▸ createPresentationJwt(storage, fragment, presentation, signature_options, presentation_options): Promise\<Jwt>
Produces a JWT where the payload is produced from the given presentation. in accordance with VC Data Model v1.1.
Unless the kid is explicitly set in the options, the kid in the protected header is the id
of the method identified by fragment and the JWS signature will be produced by the corresponding
private key backed by the storage in accordance with the passed options.
Parameters
| Name | Type |
|---|---|
storage | Storage |
fragment | string |
presentation | Presentation |
signature_options | JwsSignatureOptions |
presentation_options | JwtPresentationOptions |
Returns
Promise\<Jwt>