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

Format TypeScript/JavaScript files #1038

Merged
merged 5 commits into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions bindings/stronghold-nodejs/examples/src/stronghold.ts
@@ -1,10 +1,10 @@
import { Stronghold } from '../../dist'
import * as os from "os";
import * as path from "path";
import { Stronghold } from "../../dist";

export async function stronghold(): Promise<Stronghold> {
const random = Math.round(Math.random() * 100_000_000)
const random = Math.round(Math.random() * 100_000_000);
const strongholdPath = path.join(os.tmpdir(), "test_strongholds", `${random}.stronghodl`);
const password = "my-password";
return await Stronghold.build(strongholdPath, password, true);
}
}
8 changes: 4 additions & 4 deletions bindings/stronghold-nodejs/examples/src/tests/config.ts
@@ -1,9 +1,9 @@
import {config} from "../../../../wasm/examples-account/src/config";
import { stronghold } from '../stronghold';
import { config } from "../../../../wasm/examples-account/src/config";
import { stronghold } from "../stronghold";

// Only verifies that no uncaught exceptions are thrown, including syntax errors etc.
describe("Test Stronghold Node.js examples", function () {
describe("Test Stronghold Node.js examples", function() {
it("Config", async () => {
await config(await stronghold());
});
})
});
8 changes: 4 additions & 4 deletions bindings/stronghold-nodejs/examples/src/tests/create_did.ts
@@ -1,9 +1,9 @@
import {createIdentity} from "../../../../wasm/examples-account/src/create_did";
import { stronghold } from '../stronghold';
import { createIdentity } from "../../../../wasm/examples-account/src/create_did";
import { stronghold } from "../stronghold";

// Only verifies that no uncaught exceptions are thrown, including syntax errors etc.
describe("Test Stronghold Node.js examples", function () {
describe("Test Stronghold Node.js examples", function() {
it("Create Identity", async () => {
await createIdentity(await stronghold());
});
})
});
6 changes: 3 additions & 3 deletions bindings/stronghold-nodejs/examples/src/tests/encryption.ts
@@ -1,9 +1,9 @@
import { encryption } from "../../../../wasm/examples-account/src/encryption";
import { stronghold } from '../stronghold';
import { stronghold } from "../stronghold";

// Only verifies that no uncaught exceptions are thrown, including syntax errors etc.
describe("Test Stronghold Node.js examples", function () {
describe("Test Stronghold Node.js examples", function() {
it("encryption", async () => {
await encryption(await stronghold());
});
})
});
8 changes: 4 additions & 4 deletions bindings/stronghold-nodejs/examples/src/tests/lazy.ts
@@ -1,9 +1,9 @@
import {lazy} from "../../../../wasm/examples-account/src/lazy";
import { stronghold } from '../stronghold';
import { lazy } from "../../../../wasm/examples-account/src/lazy";
import { stronghold } from "../stronghold";

// Only verifies that no uncaught exceptions are thrown, including syntax errors etc.
describe("Test Stronghold Node.js examples", function () {
describe("Test Stronghold Node.js examples", function() {
it("Lazy", async () => {
await lazy(await stronghold());
});
})
});
@@ -1,9 +1,9 @@
import {manipulateIdentity} from "../../../../wasm/examples-account/src/manipulate_did";
import { stronghold } from '../stronghold';
import { manipulateIdentity } from "../../../../wasm/examples-account/src/manipulate_did";
import { stronghold } from "../stronghold";

// Only verifies that no uncaught exceptions are thrown, including syntax errors etc.
describe("Test Stronghold Node.js examples", function () {
describe("Test Stronghold Node.js examples", function() {
it("Manipulate DID", async () => {
await manipulateIdentity(await stronghold());
});
})
});
@@ -1,10 +1,10 @@
import {multipleIdentities} from "../../../../wasm/examples-account/src/multiple_identities";
import { stronghold } from '../stronghold';
import { multipleIdentities } from "../../../../wasm/examples-account/src/multiple_identities";
import { stronghold } from "../stronghold";

// Only verifies that no uncaught exceptions are thrown, including syntax errors etc.
describe("Test Stronghold Node.js examples", function () {
describe("Test Stronghold Node.js examples", function() {
it("Multiple Identities", async () => {
// TODO: Temporarily disabled until iotaledger/stronghold.rs#353 is fixed.
// await multipleIdentities(await stronghold());
});
})
});
6 changes: 3 additions & 3 deletions bindings/stronghold-nodejs/examples/src/tests/signing.ts
@@ -1,9 +1,9 @@
import { signing } from "../../../../wasm/examples-account/src/signing";
import { stronghold } from '../stronghold';
import { stronghold } from "../stronghold";

// Only verifies that no uncaught exceptions are thrown, including syntax errors etc.
describe("Test Stronghold Node.js examples", function () {
describe("Test Stronghold Node.js examples", function() {
it("Signing", async () => {
await signing(await stronghold());
});
})
});
@@ -1,8 +1,8 @@
import { stronghold } from '../stronghold';
import { StorageTestSuite } from '@iota/identity-wasm/node';
import { StorageTestSuite } from "@iota/identity-wasm/node";
import { stronghold } from "../stronghold";

// Only verifies that no uncaught exceptions are thrown, including syntax errors etc.
describe("Test Stronghold Node.js", function () {
describe("Test Stronghold Node.js", function() {
it("didCreateGenerateKey", async () => {
await StorageTestSuite.didCreateGenerateKeyTest(await stronghold());
});
Expand Down
8 changes: 4 additions & 4 deletions bindings/stronghold-nodejs/examples/src/tests/unchecked.ts
@@ -1,9 +1,9 @@
import {unchecked} from "../../../../wasm/examples-account/src/unchecked";
import { stronghold } from '../stronghold';
import { unchecked } from "../../../../wasm/examples-account/src/unchecked";
import { stronghold } from "../stronghold";

// Only verifies that no uncaught exceptions are thrown, including syntax errors etc.
describe("Test Stronghold Node.js examples", function () {
describe("Test Stronghold Node.js examples", function() {
it("Unchecked", async () => {
await unchecked(await stronghold());
});
})
});
4 changes: 2 additions & 2 deletions bindings/stronghold-nodejs/js/index.ts
@@ -1,2 +1,2 @@
export * from './stronghold';
export * from '../napi-dist/napi';
export * from "../napi-dist/napi";
export * from "./stronghold";
92 changes: 74 additions & 18 deletions bindings/stronghold-nodejs/js/stronghold.ts
@@ -1,25 +1,50 @@
import { NapiStronghold, NapiCoreDid, NapiDIDType, NapiKeyLocation, NapiKeyType, NapiDidLocation, NapiEncryptedData, NapiEncryptionAlgorithm, NapiCekAlgorithm } from '../napi-dist/napi';
import { CoreDID, DIDType, KeyLocation, Signature, Storage, KeyType, EncryptedData, EncryptionAlgorithm, CekAlgorithm } from "@iota/identity-wasm/node";
import {
CekAlgorithm,
CoreDID,
DIDType,
EncryptedData,
EncryptionAlgorithm,
KeyLocation,
KeyType,
Signature,
Storage,
} from "@iota/identity-wasm/node";
import {
NapiCekAlgorithm,
NapiCoreDid,
NapiDidLocation,
NapiDIDType,
NapiEncryptedData,
NapiEncryptionAlgorithm,
NapiKeyLocation,
NapiKeyType,
NapiStronghold,
} from "../napi-dist/napi";

export class Stronghold implements Storage {
private napiStronghold: NapiStronghold;

constructor() { }
constructor() {}

public async init(snapshot: string, password: string, dropsave?: boolean) {
this.napiStronghold = await NapiStronghold.new(snapshot, password, dropsave);
}

public static async build(snapshot: string, password: string, dropsave?: boolean) {
const stronghold = new Stronghold();
await stronghold.init(snapshot, password, dropsave)
return stronghold
await stronghold.init(snapshot, password, dropsave);
return stronghold;
}

public async didCreate(didType: DIDType, network: string, fragment: string, private_key?: Uint8Array): Promise<[CoreDID, KeyLocation]> {
public async didCreate(
didType: DIDType,
network: string,
fragment: string,
private_key?: Uint8Array,
): Promise<[CoreDID, KeyLocation]> {
let optPrivateKey = undefined;
if (private_key) {
optPrivateKey = Array.from(private_key)
optPrivateKey = Array.from(private_key);
}

let napiDIDType: NapiDIDType | undefined = undefined;
Expand All @@ -31,7 +56,12 @@ export class Stronghold implements Storage {
throw new Error("unexpected did type");
}

const napiDidLocation: NapiDidLocation = await this.napiStronghold.didCreate(napiDIDType, network, fragment, optPrivateKey);
const napiDidLocation: NapiDidLocation = await this.napiStronghold.didCreate(
napiDIDType,
network,
fragment,
optPrivateKey,
);

const did: CoreDID = CoreDID.fromJSON(napiDidLocation.did().toJSON());
const location: KeyLocation = KeyLocation.fromJSON(napiDidLocation.keyLocation().toJSON());
Expand All @@ -51,7 +81,7 @@ export class Stronghold implements Storage {

public async didList(): Promise<Array<CoreDID>> {
const napiDids: Array<NapiCoreDid> = await this.napiStronghold.didList();
const dids: Array<CoreDID> = napiDids.map((did) => CoreDID.fromJSON(did.toJSON()))
const dids: Array<CoreDID> = napiDids.map((did) => CoreDID.fromJSON(did.toJSON()));
return dids;
}

Expand All @@ -61,10 +91,10 @@ export class Stronghold implements Storage {
let napiKeyType: NapiKeyType | undefined = undefined;
switch (keyType) {
case KeyType.Ed25519:
napiKeyType = NapiKeyType.Ed25519
napiKeyType = NapiKeyType.Ed25519;
break;
case KeyType.X25519:
napiKeyType = NapiKeyType.X25519
napiKeyType = NapiKeyType.X25519;
break;
default:
throw new Error("unexpected key type");
Expand All @@ -83,7 +113,7 @@ export class Stronghold implements Storage {
public async keyExists(did: CoreDID, keyLocation: KeyLocation): Promise<boolean> {
const napiDID: NapiCoreDid = NapiCoreDid.fromJSON(did.toJSON());
const napiKeyLocation: NapiKeyLocation = NapiKeyLocation.fromJSON(keyLocation.toJSON());
return this.napiStronghold.keyExists(napiDID, napiKeyLocation)
return this.napiStronghold.keyExists(napiDID, napiKeyLocation);
}

public async keyPublic(did: CoreDID, keyLocation: KeyLocation): Promise<Uint8Array> {
Expand All @@ -106,21 +136,47 @@ export class Stronghold implements Storage {
return Signature.fromJSON(napiSignature.toJSON());
}

public async dataEncrypt(did: CoreDID, plaintext: Uint8Array, associatedData: Uint8Array, encryptionAlgorithm: EncryptionAlgorithm, cekAlgorithm: CekAlgorithm, publicKey: Uint8Array): Promise<EncryptedData> {
public async dataEncrypt(
did: CoreDID,
plaintext: Uint8Array,
associatedData: Uint8Array,
encryptionAlgorithm: EncryptionAlgorithm,
cekAlgorithm: CekAlgorithm,
publicKey: Uint8Array,
): Promise<EncryptedData> {
const napiDID: NapiCoreDid = NapiCoreDid.fromJSON(did.toJSON());
const napiCekAlgorithm = NapiCekAlgorithm.fromJSON(cekAlgorithm.toJSON());
const napiEncryptionAlgorithm = NapiEncryptionAlgorithm.fromJSON(encryptionAlgorithm.toJSON());
const napiEncryptedData = await this.napiStronghold.dataEncrypt(napiDID, Array.from(plaintext), Array.from(associatedData), napiEncryptionAlgorithm, napiCekAlgorithm, Array.from(publicKey));
const napiEncryptedData = await this.napiStronghold.dataEncrypt(
napiDID,
Array.from(plaintext),
Array.from(associatedData),
napiEncryptionAlgorithm,
napiCekAlgorithm,
Array.from(publicKey),
);
return EncryptedData.fromJSON(napiEncryptedData.toJSON());
}

public async dataDecrypt(did: CoreDID, data: EncryptedData, encryptionAlgorithm: EncryptionAlgorithm, cekAlgorithm: CekAlgorithm, privateKey: KeyLocation): Promise<Uint8Array> {
public async dataDecrypt(
did: CoreDID,
data: EncryptedData,
encryptionAlgorithm: EncryptionAlgorithm,
cekAlgorithm: CekAlgorithm,
privateKey: KeyLocation,
): Promise<Uint8Array> {
const napiDID: NapiCoreDid = NapiCoreDid.fromJSON(did.toJSON());
const napiPrivateKeyLocation = NapiKeyLocation.fromJSON(privateKey.toJSON());
const napiCekAlgorithm = NapiCekAlgorithm.fromJSON(cekAlgorithm.toJSON());
const napiEncryptionAlgorithm = NapiEncryptionAlgorithm.fromJSON(encryptionAlgorithm.toJSON());
const napiEncryptedData = NapiEncryptedData.fromJSON(data.toJSON());
const decryptedData = await this.napiStronghold.dataDecrypt(napiDID, napiEncryptedData, napiEncryptionAlgorithm, napiCekAlgorithm, napiPrivateKeyLocation);
const decryptedData = await this.napiStronghold.dataDecrypt(
napiDID,
napiEncryptedData,
napiEncryptionAlgorithm,
napiCekAlgorithm,
napiPrivateKeyLocation,
);
return Uint8Array.from(decryptedData);
}

Expand All @@ -129,7 +185,7 @@ export class Stronghold implements Storage {
const value: number[] | undefined = await this.napiStronghold.blobGet(napiDID);

if (value) {
return Uint8Array.from(value)
return Uint8Array.from(value);
} else {
return undefined;
}
Expand All @@ -141,6 +197,6 @@ export class Stronghold implements Storage {
}

public async flushChanges() {
return this.napiStronghold.flushChanges()
return this.napiStronghold.flushChanges();
}
}
27 changes: 13 additions & 14 deletions bindings/stronghold-nodejs/rollup.config.js
@@ -1,28 +1,27 @@
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import copy from "rollup-plugin-copy";
import dts from "rollup-plugin-dts";
import copy from 'rollup-plugin-copy'

export default [{
input: 'js/index.ts',
input: "js/index.ts",
output: {
dir: 'dist',
format: 'cjs'
dir: "dist",
format: "cjs",
},
external: ['@iota/identity-wasm/node', 'fs', 'path'], // so it's not included
external: ["@iota/identity-wasm/node", "fs", "path"], // so it's not included
plugins: [
typescript(),
commonjs(),
copy({
targets: [
{ src: 'napi-dist/*.node', dest: 'dist' }
]
})
{ src: "napi-dist/*.node", dest: "dist" },
],
}),
],
}, {
// path to your declaration files root
input: './dist/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'es' }],
input: "./dist/index.d.ts",
output: [{ file: "dist/index.d.ts", format: "es" }],
plugins: [dts()],
},
];
}];
8 changes: 4 additions & 4 deletions bindings/stronghold-nodejs/tests/txm_readme.js
@@ -1,7 +1,7 @@
const {execSync} = require('child_process')
const { execSync } = require("child_process");

describe("Test TXM", function () {
describe("Test TXM", function() {
it("README examples pass", async () => {
execSync("txm README.md")
execSync("txm README.md");
});
})
});
18 changes: 9 additions & 9 deletions bindings/wasm/build/docs.js
@@ -1,15 +1,15 @@
const fs = require('fs')
const path = require('path')
const jsdoc2md = require('jsdoc-to-markdown')
const fs = require("fs");
const path = require("path");
const jsdoc2md = require("jsdoc-to-markdown");

const importFile = path.join(__dirname, '../node/identity_wasm.js')
const exportFile = path.join(__dirname, '../docs/api-reference.md')
const importFile = path.join(__dirname, "../node/identity_wasm.js");
const exportFile = path.join(__dirname, "../docs/api-reference.md");

const docsRoot = path.join(__dirname, '../docs')
const docsData = jsdoc2md.renderSync({ files: importFile })
const docsRoot = path.join(__dirname, "../docs");
const docsData = jsdoc2md.renderSync({ files: importFile });

if (!fs.existsSync(docsRoot)) {
fs.mkdirSync(docsRoot)
fs.mkdirSync(docsRoot);
}

fs.writeFileSync(exportFile, docsData)
fs.writeFileSync(exportFile, docsData);