From c1a8a4ef802efc5b0019f70e3c3fb390e8c90842 Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 30 Sep 2024 11:20:42 -0700 Subject: [PATCH] Bind Dids --- .gitignore | 5 +- Justfile | 5 +- bindings/web5_wasm/src/crypto/dsa.rs | 1 - bindings/web5_wasm/src/crypto/key_managers.rs | 12 + bindings/web5_wasm/src/dids/bearer_did.rs | 66 +++++ bindings/web5_wasm/src/dids/did.rs | 99 ++++++++ bindings/web5_wasm/src/dids/document.rs | 237 ++++++++++++++++++ bindings/web5_wasm/src/dids/mod.rs | 4 + bindings/web5_wasm/src/dids/portable_did.rs | 71 ++++++ bindings/web5_wasm/src/lib.rs | 2 + bound/typescript/.gitignore | 47 ++++ bound/typescript/src/wasm/generated.d.ts | 204 ++++++++++++++- examples/TypeScriptExample/.gitignore | 47 ++++ examples/TypeScriptExample/index.js | 4 + examples/TypeScriptExample/index.ts | 2 + examples/TypeScriptExample/package.json | 21 ++ examples/TypeScriptExample/pnpm-lock.yaml | 34 +++ examples/TypeScriptExample/tsconfig.json | 13 + 18 files changed, 868 insertions(+), 6 deletions(-) create mode 100644 bindings/web5_wasm/src/dids/bearer_did.rs create mode 100644 bindings/web5_wasm/src/dids/did.rs create mode 100644 bindings/web5_wasm/src/dids/document.rs create mode 100644 bindings/web5_wasm/src/dids/mod.rs create mode 100644 bindings/web5_wasm/src/dids/portable_did.rs create mode 100644 bound/typescript/.gitignore create mode 100644 examples/TypeScriptExample/.gitignore create mode 100644 examples/TypeScriptExample/index.js create mode 100644 examples/TypeScriptExample/index.ts create mode 100644 examples/TypeScriptExample/package.json create mode 100644 examples/TypeScriptExample/pnpm-lock.yaml create mode 100644 examples/TypeScriptExample/tsconfig.json diff --git a/.gitignore b/.gitignore index 14e1fff7..0c4eb787 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,7 @@ bound/LICENSE bound/typescript/dist/* !bound/typescript/dist/index.js bound/typescript/tests/compiled -bound/typescript/src/wasm/generated.js \ No newline at end of file +bound/typescript/src/wasm/generated.js + +# macOS +.DS_Store \ No newline at end of file diff --git a/Justfile b/Justfile index c46fab0a..aada0549 100644 --- a/Justfile +++ b/Justfile @@ -7,8 +7,9 @@ setup: if [ ! -d ".git/modules/web5-spec" ]; then git submodule update --init --recursive fi - if [[ "$(cargo 2>&1)" == *"rustup could not choose a version of cargo to run"* ]]; then - rustup default 1.76.0 # TODO undo this + if [[ "$(cargo --version)" != "cargo 1.76.0"* ]]; then + rustup install 1.76.0 + rustup default 1.76.0 rustup target add aarch64-apple-darwin fi if ! command -v wasm-pack >/dev/null || [[ "$(wasm-pack --version)" != "wasm-pack 0.13.0" ]]; then diff --git a/bindings/web5_wasm/src/crypto/dsa.rs b/bindings/web5_wasm/src/crypto/dsa.rs index 02694399..972397d7 100644 --- a/bindings/web5_wasm/src/crypto/dsa.rs +++ b/bindings/web5_wasm/src/crypto/dsa.rs @@ -7,7 +7,6 @@ use web5::crypto::dsa::{ secp256k1::{Secp256k1Generator, Secp256k1Signer}, Signer, }; - #[wasm_bindgen] pub struct WasmSigner { inner: Arc, diff --git a/bindings/web5_wasm/src/crypto/key_managers.rs b/bindings/web5_wasm/src/crypto/key_managers.rs index 1fca0150..c27c3b1d 100644 --- a/bindings/web5_wasm/src/crypto/key_managers.rs +++ b/bindings/web5_wasm/src/crypto/key_managers.rs @@ -20,6 +20,18 @@ impl From for WasmKeyManager { } } +impl From> for WasmKeyManager { + fn from(value: Arc) -> Self { + Self { inner: value } + } +} + +impl From for Arc { + fn from(wasm_key_manager: WasmKeyManager) -> Self { + wasm_key_manager.inner + } +} + #[wasm_bindgen] impl WasmKeyManager { pub fn import_private_jwk(&self, private_jwk: WasmJwk) -> Result { diff --git a/bindings/web5_wasm/src/dids/bearer_did.rs b/bindings/web5_wasm/src/dids/bearer_did.rs new file mode 100644 index 00000000..6ba86694 --- /dev/null +++ b/bindings/web5_wasm/src/dids/bearer_did.rs @@ -0,0 +1,66 @@ +use crate::errors::{map_err, Result}; +use wasm_bindgen::prelude::wasm_bindgen; +use web5::dids::bearer_did::BearerDid; +use crate::crypto::dsa::WasmSigner; +use crate::crypto::key_managers::WasmKeyManager; +use crate::dids::did::WasmDid; +use crate::dids::document::WasmDocument; +use crate::dids::portable_did::WasmPortableDid; + +#[wasm_bindgen] +pub struct WasmBearerDid { + inner: BearerDid, +} + +impl From for BearerDid { + fn from(value: WasmBearerDid) -> Self { + value.inner + } +} + +#[wasm_bindgen] +impl WasmBearerDid { + #[wasm_bindgen(constructor)] + pub fn new(did: WasmDid, document: WasmDocument, key_manager: WasmKeyManager) -> Self { + Self { + inner: BearerDid { + did: did.into(), + document: document.into(), + key_manager: key_manager.into(), + }, + } + } + + #[wasm_bindgen] + pub fn from_portable_did(portable_did: WasmPortableDid) -> Result { + Ok(Self { + inner: BearerDid::from_portable_did(portable_did.into()).map_err(map_err)?, + }) + } + + // todo key exporter for to_portable_did + + #[wasm_bindgen] + pub fn get_signer(&self, verification_method_id: &str) -> Result { + Ok(self + .inner + .get_signer(verification_method_id) + .map_err(map_err)? + .into()) + } + + #[wasm_bindgen(getter)] + pub fn did(&self) -> WasmDid { + self.inner.did.clone().into() + } + + #[wasm_bindgen(getter)] + pub fn document(&self) -> WasmDocument { + self.inner.document.clone().into() + } + + #[wasm_bindgen(getter)] + pub fn key_manager(&self) -> WasmKeyManager { + self.inner.key_manager.clone().into() + } +} diff --git a/bindings/web5_wasm/src/dids/did.rs b/bindings/web5_wasm/src/dids/did.rs new file mode 100644 index 00000000..4583226f --- /dev/null +++ b/bindings/web5_wasm/src/dids/did.rs @@ -0,0 +1,99 @@ +use std::collections::HashMap; +use wasm_bindgen::prelude::wasm_bindgen; +use wasm_bindgen::JsValue; +use web5::dids::did::Did; + +#[wasm_bindgen] +pub struct WasmDid { + inner: Did, +} + +impl From for Did { + fn from(value: WasmDid) -> Self { + value.inner + } +} + +impl From for WasmDid { + fn from(value: Did) -> Self { + WasmDid { inner: value } + } +} + +#[wasm_bindgen] +impl WasmDid { + #[allow(clippy::too_many_arguments)] + #[wasm_bindgen(constructor)] + pub fn new( + uri: String, + url: String, + method: String, + id: String, + params: JsValue, + path: Option, + query: Option, + fragment: Option, + ) -> Self { + let params = if params.is_undefined() { + None + } else { + serde_wasm_bindgen::from_value(params).unwrap_or(Some(HashMap::new())) + }; + + Self { + inner: Did { + uri, + url, + method, + id, + params, + path, + query, + fragment, + }, + } + } + + #[wasm_bindgen(getter)] + pub fn uri(&self) -> String { + self.inner.uri.clone() + } + + #[wasm_bindgen(getter)] + pub fn url(&self) -> String { + self.inner.url.clone() + } + + #[wasm_bindgen(getter)] + pub fn method(&self) -> String { + self.inner.method.clone() + } + + #[wasm_bindgen(getter)] + pub fn id(&self) -> String { + self.inner.id.clone() + } + + #[wasm_bindgen(getter)] + pub fn params(&self) -> JsValue { + match &self.inner.params { + Some(map) => serde_wasm_bindgen::to_value(map).unwrap_or(JsValue::undefined()), + None => JsValue::undefined(), + } + } + + #[wasm_bindgen(getter)] + pub fn path(&self) -> Option { + self.inner.path.clone() + } + + #[wasm_bindgen(getter)] + pub fn query(&self) -> Option { + self.inner.query.clone() + } + + #[wasm_bindgen(getter)] + pub fn fragment(&self) -> Option { + self.inner.fragment.clone() + } +} diff --git a/bindings/web5_wasm/src/dids/document.rs b/bindings/web5_wasm/src/dids/document.rs new file mode 100644 index 00000000..5aac9f29 --- /dev/null +++ b/bindings/web5_wasm/src/dids/document.rs @@ -0,0 +1,237 @@ +use crate::errors::{map_err, Result}; +use wasm_bindgen::prelude::wasm_bindgen; +use web5::{ + dids::data_model::{ + document::Document, service::Service, verification_method::VerificationMethod, + }, + json::{FromJson, ToJson}, +}; +use crate::crypto::jwk::WasmJwk; + +#[wasm_bindgen] +pub struct WasmDocument { + inner: Document, +} + +impl From for Document { + fn from(value: WasmDocument) -> Self { + value.inner + } +} + +impl From for WasmDocument { + fn from(value: Document) -> Self { + WasmDocument { inner: value } + } +} + +#[wasm_bindgen] +impl WasmDocument { + #[allow(clippy::too_many_arguments)] + #[wasm_bindgen(constructor)] + pub fn new( + id: String, + context: Option>, + controller: Option>, + also_known_as: Option>, + verification_method: Vec, + authentication: Option>, + assertion_method: Option>, + key_agreement: Option>, + capability_invocation: Option>, + capability_delegation: Option>, + service: Option>, + ) -> Self { + Self { + inner: Document { + id, + context, + controller, + also_known_as, + verification_method: verification_method + .into_iter() + .map(|wvm| wvm.into()) + .collect(), + authentication, + assertion_method, + key_agreement, + capability_invocation, + capability_delegation, + service: service.map(|wss| wss.into_iter().map(|ws| ws.into()).collect()), + }, + } + } + + #[wasm_bindgen] + pub fn from_json_string(json: &str) -> Result { + Ok(Self { + inner: Document::from_json_string(json).map_err(map_err)?, + }) + } + + #[wasm_bindgen] + pub fn to_json_string(&self) -> Result { + self.inner.to_json_string().map_err(map_err) + } + + #[wasm_bindgen(getter)] + pub fn id(&self) -> String { + self.inner.id.clone() + } + + #[wasm_bindgen(getter)] + pub fn context(&self) -> Option> { + self.inner.context.clone() + } + + #[wasm_bindgen(getter)] + pub fn controller(&self) -> Option> { + self.inner.controller.clone() + } + + #[wasm_bindgen(getter)] + pub fn also_known_as(&self) -> Option> { + self.inner.also_known_as.clone() + } + + #[wasm_bindgen(getter)] + pub fn verification_method(&self) -> Vec { + self.inner + .verification_method + .clone() + .into_iter() + .map(|vm| vm.into()) + .collect() + } + + #[wasm_bindgen(getter)] + pub fn authentication(&self) -> Option> { + self.inner.authentication.clone() + } + + #[wasm_bindgen(getter)] + pub fn assertion_method(&self) -> Option> { + self.inner.assertion_method.clone() + } + + #[wasm_bindgen(getter)] + pub fn key_agreement(&self) -> Option> { + self.inner.key_agreement.clone() + } + + #[wasm_bindgen(getter)] + pub fn capability_invocation(&self) -> Option> { + self.inner.capability_invocation.clone() + } + + #[wasm_bindgen(getter)] + pub fn capability_delegation(&self) -> Option> { + self.inner.capability_delegation.clone() + } + + #[wasm_bindgen(getter)] + pub fn service(&self) -> Option> { + self.inner + .service + .clone() + .map(|services| services.into_iter().map(|s| s.into()).collect()) + } +} + +#[wasm_bindgen] +pub struct WasmVerificationMethod { + inner: VerificationMethod, +} + +impl From for VerificationMethod { + fn from(value: WasmVerificationMethod) -> Self { + value.inner + } +} + +impl From for WasmVerificationMethod { + fn from(value: VerificationMethod) -> Self { + Self { inner: value } + } +} + +#[wasm_bindgen] +impl WasmVerificationMethod { + #[wasm_bindgen(constructor)] + pub fn new(id: String, r#type: String, controller: String, public_key_jwk: WasmJwk) -> Self { + Self { + inner: VerificationMethod { + id, + r#type, + controller, + public_key_jwk: public_key_jwk.into(), + }, + } + } + + #[wasm_bindgen(getter)] + pub fn id(&self) -> String { + self.inner.id.clone() + } + + #[wasm_bindgen(getter)] + pub fn r#type(&self) -> String { + self.inner.r#type.clone() + } + + #[wasm_bindgen(getter)] + pub fn controller(&self) -> String { + self.inner.controller.clone() + } + + #[wasm_bindgen(getter)] + pub fn public_key_jwk(&self) -> WasmJwk { + self.inner.public_key_jwk.clone().into() + } +} + +#[wasm_bindgen] +pub struct WasmService { + inner: Service, +} + +impl From for Service { + fn from(value: WasmService) -> Self { + value.inner + } +} + +impl From for WasmService { + fn from(value: Service) -> Self { + Self { inner: value } + } +} + +#[wasm_bindgen] +impl WasmService { + #[wasm_bindgen(constructor)] + pub fn new(id: String, r#type: String, service_endpoint: Vec) -> Self { + Self { + inner: Service { + id, + r#type, + service_endpoint, + }, + } + } + + #[wasm_bindgen(getter)] + pub fn id(&self) -> String { + self.inner.id.clone() + } + + #[wasm_bindgen(getter)] + pub fn r#type(&self) -> String { + self.inner.r#type.clone() + } + + #[wasm_bindgen(getter)] + pub fn service_endpoint(&self) -> Vec { + self.inner.service_endpoint.clone() + } +} diff --git a/bindings/web5_wasm/src/dids/mod.rs b/bindings/web5_wasm/src/dids/mod.rs new file mode 100644 index 00000000..93b352ab --- /dev/null +++ b/bindings/web5_wasm/src/dids/mod.rs @@ -0,0 +1,4 @@ +pub mod bearer_did; +pub mod did; +pub mod document; +pub mod portable_did; \ No newline at end of file diff --git a/bindings/web5_wasm/src/dids/portable_did.rs b/bindings/web5_wasm/src/dids/portable_did.rs new file mode 100644 index 00000000..9493920a --- /dev/null +++ b/bindings/web5_wasm/src/dids/portable_did.rs @@ -0,0 +1,71 @@ +use crate::errors::{map_err, Result}; +use wasm_bindgen::prelude::wasm_bindgen; +use web5::{ + dids::portable_did::PortableDid, + json::{FromJson, ToJson}, +}; +use crate::crypto::jwk::WasmJwk; +use crate::dids::document::WasmDocument; + +#[wasm_bindgen] +pub struct WasmPortableDid { + inner: PortableDid, +} + +impl From for PortableDid { + fn from(value: WasmPortableDid) -> Self { + value.inner + } +} + +impl From for WasmPortableDid { + fn from(value: PortableDid) -> Self { + Self { inner: value } + } +} + +#[wasm_bindgen] +impl WasmPortableDid { + #[wasm_bindgen(constructor)] + pub fn new(did_uri: String, document: WasmDocument, private_keys: Vec) -> Self { + Self { + inner: PortableDid { + did_uri, + document: document.into(), + private_jwks: private_keys.into_iter().map(|pj| pj.into()).collect(), + }, + } + } + + #[wasm_bindgen] + pub fn from_json_string(json: &str) -> Result { + Ok(Self { + inner: PortableDid::from_json_string(json).map_err(map_err)?, + }) + } + + #[wasm_bindgen] + pub fn to_json_string(&self) -> Result { + self.inner.to_json_string().map_err(map_err) + } + + #[wasm_bindgen(getter)] + pub fn did_uri(&self) -> String { + self.inner.did_uri.clone() + } + + #[wasm_bindgen(getter)] + pub fn document(&self) -> WasmDocument { + self.inner.document.clone().into() + } + + #[wasm_bindgen(getter)] + pub fn private_keys(&self) -> Vec { + self.inner + .private_jwks + .clone() + .into_iter() + .map(|j| j.into()) + .collect() + } +} diff --git a/bindings/web5_wasm/src/lib.rs b/bindings/web5_wasm/src/lib.rs index 09336a54..26ef6aab 100644 --- a/bindings/web5_wasm/src/lib.rs +++ b/bindings/web5_wasm/src/lib.rs @@ -1,3 +1,5 @@ pub mod crypto; pub mod errors; + +pub mod dids; \ No newline at end of file diff --git a/bound/typescript/.gitignore b/bound/typescript/.gitignore new file mode 100644 index 00000000..a38a51a9 --- /dev/null +++ b/bound/typescript/.gitignore @@ -0,0 +1,47 @@ +# Node.js +node_modules/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +package-lock.json +yarn.lock +.pnpm-debug.log + +# Typescript +dist/ +*.tsbuildinfo + +# Logs +logs +*.log +logs/* + +# OS generated files +.DS_Store +Thumbs.db + +# IDEs and Editors +.vscode/ +.idea/ +*.suo +*.ntvs* +*.njsproj +*.sln + +# Testing +coverage/ + +# Optional npm cache directory +.npm/ +.npmrc + +# TypeScript cache +*.tsbuildinfo + +# Mac system files +.DS_Store + +# Environment variables +.env +.env.* diff --git a/bound/typescript/src/wasm/generated.d.ts b/bound/typescript/src/wasm/generated.d.ts index 4492c1e1..26bc1676 100644 --- a/bound/typescript/src/wasm/generated.d.ts +++ b/bound/typescript/src/wasm/generated.d.ts @@ -28,9 +28,136 @@ export function new_ed25519_signer(jwk: WasmJwk): WasmSigner; */ export function new_secp256k1_signer(jwk: WasmJwk): WasmSigner; /** -* @param {{hello1: Function, hello2: Function}} obj */ -export function call_js_functions(obj: {hello1: Function, hello2: Function}): void; +export class WasmBearerDid { + free(): void; +/** +* @param {WasmDid} did +* @param {WasmDocument} document +* @param {WasmKeyManager} key_manager +*/ + constructor(did: WasmDid, document: WasmDocument, key_manager: WasmKeyManager); +/** +* @param {WasmPortableDid} portable_did +* @returns {WasmBearerDid} +*/ + static from_portable_did(portable_did: WasmPortableDid): WasmBearerDid; +/** +* @param {string} verification_method_id +* @returns {WasmSigner} +*/ + get_signer(verification_method_id: string): WasmSigner; +/** +*/ + readonly did: WasmDid; +/** +*/ + readonly document: WasmDocument; +/** +*/ + readonly key_manager: WasmKeyManager; +} +/** +*/ +export class WasmDid { + free(): void; +/** +* @param {string} uri +* @param {string} url +* @param {string} method +* @param {string} id +* @param {any} params +* @param {string | undefined} [path] +* @param {string | undefined} [query] +* @param {string | undefined} [fragment] +*/ + constructor(uri: string, url: string, method: string, id: string, params: any, path?: string, query?: string, fragment?: string); +/** +*/ + readonly fragment: string | undefined; +/** +*/ + readonly id: string; +/** +*/ + readonly method: string; +/** +*/ + readonly params: any; +/** +*/ + readonly path: string | undefined; +/** +*/ + readonly query: string | undefined; +/** +*/ + readonly uri: string; +/** +*/ + readonly url: string; +} +/** +*/ +export class WasmDocument { + free(): void; +/** +* @param {string} id +* @param {(string)[] | undefined} context +* @param {(string)[] | undefined} controller +* @param {(string)[] | undefined} also_known_as +* @param {(WasmVerificationMethod)[]} verification_method +* @param {(string)[] | undefined} [authentication] +* @param {(string)[] | undefined} [assertion_method] +* @param {(string)[] | undefined} [key_agreement] +* @param {(string)[] | undefined} [capability_invocation] +* @param {(string)[] | undefined} [capability_delegation] +* @param {(WasmService)[] | undefined} [service] +*/ + constructor(id: string, context: (string)[] | undefined, controller: (string)[] | undefined, also_known_as: (string)[] | undefined, verification_method: (WasmVerificationMethod)[], authentication?: (string)[], assertion_method?: (string)[], key_agreement?: (string)[], capability_invocation?: (string)[], capability_delegation?: (string)[], service?: (WasmService)[]); +/** +* @param {string} json +* @returns {WasmDocument} +*/ + static from_json_string(json: string): WasmDocument; +/** +* @returns {string} +*/ + to_json_string(): string; +/** +*/ + readonly also_known_as: (string)[] | undefined; +/** +*/ + readonly assertion_method: (string)[] | undefined; +/** +*/ + readonly authentication: (string)[] | undefined; +/** +*/ + readonly capability_delegation: (string)[] | undefined; +/** +*/ + readonly capability_invocation: (string)[] | undefined; +/** +*/ + readonly context: (string)[] | undefined; +/** +*/ + readonly controller: (string)[] | undefined; +/** +*/ + readonly id: string; +/** +*/ + readonly key_agreement: (string)[] | undefined; +/** +*/ + readonly service: (WasmService)[] | undefined; +/** +*/ + readonly verification_method: (WasmVerificationMethod)[]; +} /** */ export class WasmJwk { @@ -84,6 +211,55 @@ export class WasmKeyManager { } /** */ +export class WasmPortableDid { + free(): void; +/** +* @param {string} did_uri +* @param {WasmDocument} document +* @param {(WasmJwk)[]} private_keys +*/ + constructor(did_uri: string, document: WasmDocument, private_keys: (WasmJwk)[]); +/** +* @param {string} json +* @returns {WasmPortableDid} +*/ + static from_json_string(json: string): WasmPortableDid; +/** +* @returns {string} +*/ + to_json_string(): string; +/** +*/ + readonly did_uri: string; +/** +*/ + readonly document: WasmDocument; +/** +*/ + readonly private_keys: (WasmJwk)[]; +} +/** +*/ +export class WasmService { + free(): void; +/** +* @param {string} id +* @param {string} type +* @param {(string)[]} service_endpoint +*/ + constructor(id: string, type: string, service_endpoint: (string)[]); +/** +*/ + readonly id: string; +/** +*/ + readonly service_endpoint: (string)[]; +/** +*/ + readonly type: string; +} +/** +*/ export class WasmSigner { free(): void; /** @@ -94,6 +270,30 @@ export class WasmSigner { } /** */ +export class WasmVerificationMethod { + free(): void; +/** +* @param {string} id +* @param {string} type +* @param {string} controller +* @param {WasmJwk} public_key_jwk +*/ + constructor(id: string, type: string, controller: string, public_key_jwk: WasmJwk); +/** +*/ + readonly controller: string; +/** +*/ + readonly id: string; +/** +*/ + readonly public_key_jwk: WasmJwk; +/** +*/ + readonly type: string; +} +/** +*/ export class WasmWeb5Error { free(): void; /** diff --git a/examples/TypeScriptExample/.gitignore b/examples/TypeScriptExample/.gitignore new file mode 100644 index 00000000..a38a51a9 --- /dev/null +++ b/examples/TypeScriptExample/.gitignore @@ -0,0 +1,47 @@ +# Node.js +node_modules/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +package-lock.json +yarn.lock +.pnpm-debug.log + +# Typescript +dist/ +*.tsbuildinfo + +# Logs +logs +*.log +logs/* + +# OS generated files +.DS_Store +Thumbs.db + +# IDEs and Editors +.vscode/ +.idea/ +*.suo +*.ntvs* +*.njsproj +*.sln + +# Testing +coverage/ + +# Optional npm cache directory +.npm/ +.npmrc + +# TypeScript cache +*.tsbuildinfo + +# Mac system files +.DS_Store + +# Environment variables +.env +.env.* diff --git a/examples/TypeScriptExample/index.js b/examples/TypeScriptExample/index.js new file mode 100644 index 00000000..6f4d9150 --- /dev/null +++ b/examples/TypeScriptExample/index.js @@ -0,0 +1,4 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const web5_1 = require("web5"); +console.log(web5_1.dids); diff --git a/examples/TypeScriptExample/index.ts b/examples/TypeScriptExample/index.ts new file mode 100644 index 00000000..d3473601 --- /dev/null +++ b/examples/TypeScriptExample/index.ts @@ -0,0 +1,2 @@ +import { generate_ed25519_key } from '../../bound/typescript/dist/web5_wasm'; +console.log(generate_ed25519_key()); \ No newline at end of file diff --git a/examples/TypeScriptExample/package.json b/examples/TypeScriptExample/package.json new file mode 100644 index 00000000..855b0db6 --- /dev/null +++ b/examples/TypeScriptExample/package.json @@ -0,0 +1,21 @@ +{ + "name": "typescriptexample", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build": "tsc", + "start": "node dist/index.js" + }, + "keywords": [], + "author": "", + "type": "module", + "license": "ISC", + "description": "", + "dependencies": { + "web5": "../../bound/typescript" + }, + "devDependencies": { + "typescript": "^5.6.2" + } +} diff --git a/examples/TypeScriptExample/pnpm-lock.yaml b/examples/TypeScriptExample/pnpm-lock.yaml new file mode 100644 index 00000000..790ffded --- /dev/null +++ b/examples/TypeScriptExample/pnpm-lock.yaml @@ -0,0 +1,34 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + web5: + specifier: file:/Users/nealr/MY-WORKSPACE/WEB5-RS/web5-rs/bound/typescript + version: file:../../bound/typescript + devDependencies: + typescript: + specifier: ^5.6.2 + version: 5.6.2 + +packages: + + typescript@5.6.2: + resolution: {integrity: sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==} + engines: {node: '>=14.17'} + hasBin: true + + web5@file:../../bound/typescript: + resolution: {directory: ../../bound/typescript, type: directory} + engines: {node: '>= 18'} + +snapshots: + + typescript@5.6.2: {} + + web5@file:../../bound/typescript: {} diff --git a/examples/TypeScriptExample/tsconfig.json b/examples/TypeScriptExample/tsconfig.json new file mode 100644 index 00000000..150cbbd3 --- /dev/null +++ b/examples/TypeScriptExample/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "commonjs", + "outDir": "./dist", + "rootDir": "./", + "strict": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true + }, + "include": ["./**/*.ts"], + "exclude": ["node_modules"] +}