Skip to content

Commit

Permalink
Change Storage to store arbitrary blobs (#953)
Browse files Browse the repository at this point in the history
* Add arbitrary bytes storage

* Add arbitrary storage for bindings

* Fix naming for storage function

* Bump MSRV to 1.62

* Remove serde_json dependency; Rename value to blob; Take ownership of blob; Fix bindings

* Fix doc comments
  • Loading branch information
Henrique Nogara authored Jul 26, 2022
1 parent 180519c commit f05fc56
Show file tree
Hide file tree
Showing 15 changed files with 298 additions and 322 deletions.
156 changes: 125 additions & 31 deletions bindings/stronghold-nodejs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 7 additions & 25 deletions bindings/stronghold-nodejs/js/stronghold.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NapiStronghold, NapiDid, NapiKeyLocation, NapiChainState, NapiDocument, NapiKeyType, NapiDidLocation, NapiEncryptedData, NapiEncryptionAlgorithm, NapiCekAlgorithm } from '../napi-dist/napi';
import { NapiStronghold, NapiDid, NapiKeyLocation, NapiKeyType, NapiDidLocation, NapiEncryptedData, NapiEncryptionAlgorithm, NapiCekAlgorithm } from '../napi-dist/napi';
import { DID, KeyLocation, Signature, ChainState, Storage, KeyType, Document, EncryptedData, EncryptionAlgorithm, CekAlgorithm } from "@iota/identity-wasm/node";

export class Stronghold implements Storage {
Expand Down Expand Up @@ -115,38 +115,20 @@ export class Stronghold implements Storage {
return Uint8Array.from(decryptedData);
}

public async chainStateGet(did: DID): Promise<ChainState | undefined> {
public async blobGet(did: DID): Promise<Uint8Array | undefined> {
const napiDID: NapiDid = NapiDid.fromJSON(did.toJSON());
const napiChainState: NapiChainState | undefined = await this.napiStronghold.chainStateGet(napiDID);
const value: number[] | undefined = await this.napiStronghold.blobGet(napiDID);

if (napiChainState) {
return ChainState.fromJSON(napiChainState.toJSON())
if (value) {
return Uint8Array.from(value)
} else {
return undefined;
}
}

public async chainStateSet(did: DID, chainState: ChainState): Promise<void> {
public async blobSet(did: DID, value: Uint8Array): Promise<void> {
const napiDID: NapiDid = NapiDid.fromJSON(did.toJSON());
const napiChainState: NapiChainState = NapiChainState.fromJSON(chainState.toJSON());
return this.napiStronghold.chainStateSet(napiDID, napiChainState);
}

public async documentGet(did: DID): Promise<Document | undefined> {
const napiDID: NapiDid = NapiDid.fromJSON(did.toJSON());
const napiDocument: NapiDocument | undefined = await this.napiStronghold.documentGet(napiDID);

if (napiDocument) {
return Document.fromJSON(napiDocument.toJSON())
} else {
return undefined;
}
}

public async documentSet(did: DID, document: Document): Promise<void> {
const napiDID: NapiDid = NapiDid.fromJSON(did.toJSON());
const napiDocument: NapiDocument = NapiDocument.fromJSON(document.toJSON());
return this.napiStronghold.documentSet(napiDID, napiDocument);
return this.napiStronghold.blobSet(napiDID, Array.from(value));
}

public async flushChanges() {
Expand Down
Loading

0 comments on commit f05fc56

Please sign in to comment.