diff --git a/example/index.ts b/example/index.ts index 0e23ebf..f574a05 100644 --- a/example/index.ts +++ b/example/index.ts @@ -1,5 +1,5 @@ import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-singleton"; -import { MinaLedgerJS, Networks, TxType } from "../src/"; +import { MinaLedgerJS, Networks, TxType, isValidAddress } from "../src/"; const getAppVersion = async (instance: any) => { const version = await instance.getAppVersion(); @@ -42,13 +42,17 @@ const getDelegation = async (instance: any) => { }); console.log(signature); }; +const validateAddress = () => { + const isValid = isValidAddress("B62qr9pMrhSwBA6txJ8kD3f9GZ3VQPoUaFnKhEosdJmnZXXKj6qhkGF"); + console.log(isValid); +} (async () => { - console.log(` - + console.log(` + >> mina-ledger-js usage example on Node: - + `) const transport = await TransportNodeHid.create(); @@ -58,4 +62,5 @@ const getDelegation = async (instance: any) => { await getAddress(instance); await getDelegation(instance); await getSignature(instance); + validateAddress(); })(); diff --git a/src/index.ts b/src/index.ts index f1c66f3..f2de989 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ export { MinaLedgerJS } from "./lib"; +export { isValidAddress } from "./utils"; export * from "./types"; diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..1660074 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,8 @@ +/* + * Validate a Mina address. + */ +export const isValidAddress = (address: string): boolean => { + const regex = new RegExp("^B62q[i-s][A-HJ-NP-Za-km-z1-9]{50}$"); + + return regex.test(address); +};