@nockchain/sdk 0.1.4-nightly

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # `@nockchain/sdk`
2
+
3
+ TypeScript SDK for interacting with the **Iris** browser wallet extension (Nockchain).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i @nockchain/sdk
9
+ ```
10
+
11
+ ## What you get
12
+
13
+ - **`NockchainProvider`**: connect to Iris and request signatures / transactions (EIP-1193-ish API).
14
+ - **`TransactionBuilder`**: small fluent helper for constructing the simple “send transaction” payload.
15
+ - **WASM**: use `@nockchain/rose-wasm` directly for `TxBuilder`, `GrpcClient`, etc.
16
+ - **React Hook**: `useIris()` for one-time WASM init + gRPC client + provider wiring.
17
+
18
+ ## Basic usage (provider)
19
+
20
+ ```ts
21
+ import { NockchainProvider } from '@nockchain/sdk';
22
+
23
+ const provider = new NockchainProvider();
24
+ const { pkh, grpcEndpoint } = await provider.connect();
25
+
26
+ const sig = await provider.signMessage('hello');
27
+ console.log(sig.signature, sig.publicKeyHex);
28
+ ```
29
+
30
+ ## Building a simple transaction payload
31
+
32
+ ```ts
33
+ import { NockchainProvider, TransactionBuilder } from '@nockchain/sdk';
34
+
35
+ const provider = new NockchainProvider();
36
+ await provider.connect();
37
+
38
+ const tx = new TransactionBuilder().to('...recipient_pkh...').amount(1_000_000).build();
39
+ const txId = await provider.sendTransaction(tx);
40
+ ```
41
+
42
+ ## WASM / raw transaction signing
43
+
44
+ If you’re using `@nockchain/rose-wasm` types like `TxBuilder`, import them directly:
45
+
46
+ ```ts
47
+ import {
48
+ TxBuilder,
49
+ Pkh,
50
+ SpendCondition,
51
+ Digest,
52
+ GrpcClient,
53
+ RawTx,
54
+ Note,
55
+ } from '@nockchain/rose-wasm/rose_wasm.js';
56
+ import { NockchainProvider } from '@nockchain/sdk';
57
+ ```
58
+
59
+ See `sdk/examples/` for an end-to-end example of building + signing a raw transaction.
60
+
61
+ ## React: `useIris` hook
62
+
63
+ ```tsx
64
+ import { useIris } from '@nockchain/sdk';
65
+
66
+ export function App() {
67
+ const { provider, rpcClient, status, error, isReady } = useIris({
68
+ rpcUrl: 'https://rpc.nockbox.org',
69
+ });
70
+
71
+ if (status === 'loading') return <div>Loading…</div>;
72
+ if (status === 'error') return <pre>{String(error)}</pre>;
73
+ if (!isReady) return null;
74
+
75
+ return <div>Ready: {String(!!provider && !!rpcClient)}</div>;
76
+ }
77
+ ```
78
+
79
+ Notes:
80
+
81
+ - `react` is a **peer dependency** (you bring your own React).
82
+ - The hook initializes WASM once per page load (safe for StrictMode/HMR).
83
+
84
+ ## Development notes (this monorepo)
85
+
86
+ This SDK is built with `tsc` and publishes **compiled output** from `sdk/dist/`.
87
+
88
+ If you are iterating on `@nockchain/rose-wasm`, the recommended workflow is to publish it to a **local npm registry** (e.g. Verdaccio), then publish `@nockchain/sdk` against that version, and finally consume Iris using normal semver dependencies (no `file:`).
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Provider method constants for Nockchain wallet
3
+ * These methods can be called by dApps via window.nockchain
4
+ */
5
+ export declare const PROVIDER_METHODS: {
6
+ /** Connect to the wallet and request access */
7
+ readonly CONNECT: "nock_connect";
8
+ /** Sign an arbitrary message */
9
+ readonly SIGN_MESSAGE: "nock_signMessage";
10
+ /** Sign and send a transaction */
11
+ readonly SEND_TRANSACTION: "nock_sendTransaction";
12
+ /** Get wallet information (PKH + gRPC endpoint) */
13
+ readonly GET_WALLET_INFO: "nock_getWalletInfo";
14
+ /** Sign a raw transaction */
15
+ readonly SIGN_RAW_TX: "nock_signRawTx";
16
+ /** v0 migration: check if v0 seed is stored */
17
+ readonly MIGRATE_V0_GET_STATUS: "nock_migrateV0GetStatus";
18
+ /** v0 migration: sign a raw tx with stored v0 key */
19
+ readonly MIGRATE_V0_SIGN_RAW_TX: "nock_migrateV0SignRawTx";
20
+ };
21
+ export type ProviderMethod = (typeof PROVIDER_METHODS)[keyof typeof PROVIDER_METHODS];
22
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;IAC3B,+CAA+C;;IAG/C,gCAAgC;;IAGhC,kCAAkC;;IAGlC,mDAAmD;;IAGnD,6BAA6B;;IAG7B,+CAA+C;;IAG/C,qDAAqD;;CAE7C,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Provider method constants for Nockchain wallet
3
+ * These methods can be called by dApps via window.nockchain
4
+ */
5
+ export const PROVIDER_METHODS = {
6
+ /** Connect to the wallet and request access */
7
+ CONNECT: 'nock_connect',
8
+ /** Sign an arbitrary message */
9
+ SIGN_MESSAGE: 'nock_signMessage',
10
+ /** Sign and send a transaction */
11
+ SEND_TRANSACTION: 'nock_sendTransaction',
12
+ /** Get wallet information (PKH + gRPC endpoint) */
13
+ GET_WALLET_INFO: 'nock_getWalletInfo',
14
+ /** Sign a raw transaction */
15
+ SIGN_RAW_TX: 'nock_signRawTx',
16
+ /** v0 migration: check if v0 seed is stored */
17
+ MIGRATE_V0_GET_STATUS: 'nock_migrateV0GetStatus',
18
+ /** v0 migration: sign a raw tx with stored v0 key */
19
+ MIGRATE_V0_SIGN_RAW_TX: 'nock_migrateV0SignRawTx',
20
+ };
21
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,+CAA+C;IAC/C,OAAO,EAAE,cAAc;IAEvB,gCAAgC;IAChC,YAAY,EAAE,kBAAkB;IAEhC,kCAAkC;IAClC,gBAAgB,EAAE,sBAAsB;IAExC,mDAAmD;IACnD,eAAe,EAAE,oBAAoB;IAErC,6BAA6B;IAC7B,WAAW,EAAE,gBAAgB;IAE7B,+CAA+C;IAC/C,qBAAqB,EAAE,yBAAyB;IAEhD,qDAAqD;IACrD,sBAAsB,EAAE,yBAAyB;CACzC,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Custom error classes for Iris SDK
3
+ */
4
+ /**
5
+ * Thrown when the Iris wallet extension is not installed
6
+ */
7
+ export declare class WalletNotInstalledError extends Error {
8
+ constructor();
9
+ }
10
+ /**
11
+ * Thrown when the user rejects a transaction or request
12
+ */
13
+ export declare class UserRejectedError extends Error {
14
+ constructor(message?: string);
15
+ }
16
+ /**
17
+ * Thrown when an invalid Nockchain address is provided
18
+ */
19
+ export declare class InvalidAddressError extends Error {
20
+ constructor(address: string);
21
+ }
22
+ /**
23
+ * Thrown when transaction building fails due to missing or invalid fields
24
+ */
25
+ export declare class InvalidTransactionError extends Error {
26
+ constructor(message: string);
27
+ }
28
+ /**
29
+ * Thrown when a method is called that requires an account, but no account is connected
30
+ */
31
+ export declare class NoAccountError extends Error {
32
+ constructor();
33
+ }
34
+ /**
35
+ * Thrown when the RPC request to the extension fails
36
+ */
37
+ export declare class RpcError extends Error {
38
+ code: number;
39
+ data?: unknown;
40
+ constructor(code: number, message: string, data?: unknown);
41
+ }
42
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;;CAMjD;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,SAA8B;CAKlD;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;;CAMxC;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CAO1D"}
package/dist/errors.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Custom error classes for Iris SDK
3
+ */
4
+ /**
5
+ * Thrown when the Iris wallet extension is not installed
6
+ */
7
+ export class WalletNotInstalledError extends Error {
8
+ constructor() {
9
+ super('Iris wallet extension not installed. Please install it from the Chrome Web Store.');
10
+ this.name = 'WalletNotInstalledError';
11
+ Object.setPrototypeOf(this, WalletNotInstalledError.prototype);
12
+ }
13
+ }
14
+ /**
15
+ * Thrown when the user rejects a transaction or request
16
+ */
17
+ export class UserRejectedError extends Error {
18
+ constructor(message = 'User rejected the request') {
19
+ super(message);
20
+ this.name = 'UserRejectedError';
21
+ Object.setPrototypeOf(this, UserRejectedError.prototype);
22
+ }
23
+ }
24
+ /**
25
+ * Thrown when an invalid Nockchain address is provided
26
+ */
27
+ export class InvalidAddressError extends Error {
28
+ constructor(address) {
29
+ super(`Invalid Nockchain address: ${address}`);
30
+ this.name = 'InvalidAddressError';
31
+ Object.setPrototypeOf(this, InvalidAddressError.prototype);
32
+ }
33
+ }
34
+ /**
35
+ * Thrown when transaction building fails due to missing or invalid fields
36
+ */
37
+ export class InvalidTransactionError extends Error {
38
+ constructor(message) {
39
+ super(message);
40
+ this.name = 'InvalidTransactionError';
41
+ Object.setPrototypeOf(this, InvalidTransactionError.prototype);
42
+ }
43
+ }
44
+ /**
45
+ * Thrown when a method is called that requires an account, but no account is connected
46
+ */
47
+ export class NoAccountError extends Error {
48
+ constructor() {
49
+ super('No account connected. Call requestAccounts() first.');
50
+ this.name = 'NoAccountError';
51
+ Object.setPrototypeOf(this, NoAccountError.prototype);
52
+ }
53
+ }
54
+ /**
55
+ * Thrown when the RPC request to the extension fails
56
+ */
57
+ export class RpcError extends Error {
58
+ constructor(code, message, data) {
59
+ super(message);
60
+ this.name = 'RpcError';
61
+ this.code = code;
62
+ this.data = data;
63
+ Object.setPrototypeOf(this, RpcError.prototype);
64
+ }
65
+ }
66
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD;QACE,KAAK,CAAC,mFAAmF,CAAC,CAAC;QAC3F,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAO,GAAG,2BAA2B;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,8BAA8B,OAAO,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC;QACE,KAAK,CAAC,qDAAqD,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAIjC,YAAY,IAAY,EAAE,OAAe,EAAE,IAAc;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from './use-rose.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './use-rose.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { NockchainProvider } from '../provider.js';
2
+ import initWasm, { GrpcClient } from '@nockbox/iris-wasm/iris_wasm.js';
3
+ export type UseIrisStatus = 'idle' | 'loading' | 'ready' | 'error';
4
+ export declare function useIris({ rpcUrl }?: {
5
+ rpcUrl?: string;
6
+ }): {
7
+ provider: NockchainProvider | null;
8
+ rpcClient: GrpcClient | null;
9
+ wasm: typeof initWasm;
10
+ status: UseIrisStatus;
11
+ error: unknown;
12
+ isReady: boolean;
13
+ };
14
+ //# sourceMappingURL=use-iris.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-iris.d.ts","sourceRoot":"","sources":["../../src/hooks/use-iris.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AA6CvE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAEnE,wBAAgB,OAAO,CAAC,EAAE,MAAkC,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO;;;;;;;EAuCvF"}
@@ -0,0 +1,72 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import { NockchainProvider } from '../provider.js';
3
+ import initWasm, { GrpcClient } from '@nockbox/iris-wasm/iris_wasm.js';
4
+ const IRIS_SDK_WASM_INIT_KEY = '__nockbox_iris_sdk_wasm_init_promise__';
5
+ const IRIS_SDK_PROVIDER_KEY = '__nockbox_iris_sdk_provider__';
6
+ function ensureWasmInitializedOnce() {
7
+ const g = globalThis;
8
+ const existing = g[IRIS_SDK_WASM_INIT_KEY];
9
+ if (existing && existing instanceof Promise) {
10
+ return existing.catch(err => {
11
+ if (g[IRIS_SDK_WASM_INIT_KEY] === existing) {
12
+ delete g[IRIS_SDK_WASM_INIT_KEY];
13
+ }
14
+ throw err;
15
+ });
16
+ }
17
+ const p = initWasm().catch(err => {
18
+ if (g[IRIS_SDK_WASM_INIT_KEY] === p) {
19
+ delete g[IRIS_SDK_WASM_INIT_KEY];
20
+ }
21
+ throw err;
22
+ });
23
+ g[IRIS_SDK_WASM_INIT_KEY] = p;
24
+ return p;
25
+ }
26
+ function getProviderOnce() {
27
+ const g = globalThis;
28
+ const existing = g[IRIS_SDK_PROVIDER_KEY];
29
+ if (existing instanceof NockchainProvider)
30
+ return existing;
31
+ const provider = new NockchainProvider();
32
+ g[IRIS_SDK_PROVIDER_KEY] = provider;
33
+ return provider;
34
+ }
35
+ export function useIris({ rpcUrl = 'https://rpc.nockbox.org' } = {}) {
36
+ const [provider, setProvider] = useState(null);
37
+ const [rpcClient, setRpcClient] = useState(null);
38
+ const [status, setStatus] = useState('idle');
39
+ const [error, setError] = useState(null);
40
+ const options = useMemo(() => ({ rpcUrl }), [rpcUrl]);
41
+ useEffect(() => {
42
+ let cancelled = false;
43
+ setStatus('loading');
44
+ setError(null);
45
+ ensureWasmInitializedOnce()
46
+ .then(() => {
47
+ if (cancelled)
48
+ return;
49
+ setProvider(getProviderOnce());
50
+ setRpcClient(new GrpcClient(options.rpcUrl));
51
+ setStatus('ready');
52
+ })
53
+ .catch(err => {
54
+ if (cancelled)
55
+ return;
56
+ setError(err);
57
+ setStatus('error');
58
+ });
59
+ return () => {
60
+ cancelled = true;
61
+ };
62
+ }, [options]);
63
+ return {
64
+ provider,
65
+ rpcClient,
66
+ wasm: initWasm,
67
+ status,
68
+ error,
69
+ isReady: status === 'ready',
70
+ };
71
+ }
72
+ //# sourceMappingURL=use-iris.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-iris.js","sourceRoot":"","sources":["../../src/hooks/use-iris.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,QAAQ,EAAE,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAEvE,MAAM,sBAAsB,GAAG,wCAAwC,CAAC;AACxE,MAAM,qBAAqB,GAAG,+BAA+B,CAAC;AAQ9D,SAAS,yBAAyB;IAChC,MAAM,CAAC,GAA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AAC,CAAC;IACpE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAgB,MAAM,CAAC,CAAC;IAC5D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAU,IAAI,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEtD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,SAAS,CAAC,SAAS,CAAC,CAAC;QACrB,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEf,yBAAyB,EAAE;aACxB,IAAI,CAAC,GAAG,EAAE;YACT,IAAI,SAAS;gBAAE,OAAO;YACtB,WAAW,CAAC,eAAe,EAAE,CAAC,CAAC;YAC/B,YAAY,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;YAC7C,SAAS,CAAC,OAAO,CAAC,CAAC;QACrB,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,CAAC,EAAE;YACX,IAAI,SAAS;gBAAE,OAAO;YACtB,QAAQ,CAAC,GAAG,CAAC,CAAC;YACd,SAAS,CAAC,OAAO,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;QAEL,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO;QACL,QAAQ;QACR,SAAS;QACT,IAAI,EAAE,QAAQ;QACd,MAAM;QACN,KAAK;QACL,OAAO,EAAE,MAAM,KAAK,OAAO;KAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { NockchainProvider } from '../provider.js';
2
+ import initWasm from '@nockchain/sdk/wasm';
3
+ export type UseRoseStatus = 'idle' | 'loading' | 'ready' | 'error';
4
+ export declare function useRose({ rpcUrl }?: {
5
+ rpcUrl?: string;
6
+ }): {
7
+ provider: NockchainProvider | null;
8
+ rpcClient: unknown;
9
+ wasm: typeof initWasm;
10
+ status: UseRoseStatus;
11
+ error: unknown;
12
+ isReady: boolean;
13
+ };
14
+ //# sourceMappingURL=use-rose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-rose.d.ts","sourceRoot":"","sources":["../../src/hooks/use-rose.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AA8C3C,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAEnE,wBAAgB,OAAO,CAAC,EAAE,MAAkC,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO;;;;;;;EA2CvF"}
@@ -0,0 +1,75 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import { NockchainProvider } from '../provider.js';
3
+ import initWasm from '@nockchain/sdk/wasm';
4
+ import * as wasm from '@nockchain/sdk/wasm';
5
+ const ROSE_SDK_WASM_INIT_KEY = '__nockchain_rose_sdk_wasm_init_promise__';
6
+ const ROSE_SDK_PROVIDER_KEY = '__nockchain_rose_sdk_provider__';
7
+ function ensureWasmInitializedOnce() {
8
+ const g = globalThis;
9
+ const existing = g[ROSE_SDK_WASM_INIT_KEY];
10
+ if (existing && existing instanceof Promise) {
11
+ return existing.catch((err) => {
12
+ if (g[ROSE_SDK_WASM_INIT_KEY] === existing) {
13
+ delete g[ROSE_SDK_WASM_INIT_KEY];
14
+ }
15
+ throw err;
16
+ });
17
+ }
18
+ const p = initWasm().catch((err) => {
19
+ if (g[ROSE_SDK_WASM_INIT_KEY] === p) {
20
+ delete g[ROSE_SDK_WASM_INIT_KEY];
21
+ }
22
+ throw err;
23
+ });
24
+ g[ROSE_SDK_WASM_INIT_KEY] = p;
25
+ return p;
26
+ }
27
+ function getProviderOnce() {
28
+ const g = globalThis;
29
+ const existing = g[ROSE_SDK_PROVIDER_KEY];
30
+ if (existing instanceof NockchainProvider)
31
+ return existing;
32
+ const provider = new NockchainProvider();
33
+ g[ROSE_SDK_PROVIDER_KEY] = provider;
34
+ return provider;
35
+ }
36
+ export function useRose({ rpcUrl = 'https://rpc.nockbox.org' } = {}) {
37
+ const [provider, setProvider] = useState(null);
38
+ const [rpcClient, setRpcClient] = useState(null);
39
+ const [status, setStatus] = useState('idle');
40
+ const [error, setError] = useState(null);
41
+ const options = useMemo(() => ({ rpcUrl }), [rpcUrl]);
42
+ useEffect(() => {
43
+ let cancelled = false;
44
+ setStatus('loading');
45
+ setError(null);
46
+ ensureWasmInitializedOnce()
47
+ .then(() => {
48
+ if (cancelled)
49
+ return;
50
+ setProvider(getProviderOnce());
51
+ // The wasm package's type surface may lag runtime exports; keep this resilient.
52
+ const GrpcClientCtor = wasm.GrpcClient;
53
+ setRpcClient(GrpcClientCtor ? new GrpcClientCtor(options.rpcUrl) : null);
54
+ setStatus('ready');
55
+ })
56
+ .catch((err) => {
57
+ if (cancelled)
58
+ return;
59
+ setError(err);
60
+ setStatus('error');
61
+ });
62
+ return () => {
63
+ cancelled = true;
64
+ };
65
+ }, [options]);
66
+ return {
67
+ provider,
68
+ rpcClient,
69
+ wasm: initWasm,
70
+ status,
71
+ error,
72
+ isReady: status === 'ready',
73
+ };
74
+ }
75
+ //# sourceMappingURL=use-rose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-rose.js","sourceRoot":"","sources":["../../src/hooks/use-rose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAC3C,OAAO,KAAK,IAAI,MAAM,qBAAqB,C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AAO;QACL,QAAQ;QACR,SAAS;QACT,IAAI,EAAE,QAAQ;QACd,MAAM;QACN,KAAK;QACL,OAAO,EAAE,MAAM,KAAK,OAAO;KAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Iris Wallet SDK
3
+ * TypeScript SDK for interacting with Iris wallet extension
4
+ */
5
+ export * from './types.js';
6
+ export * from './provider.js';
7
+ export * from './transaction.js';
8
+ export * from './errors.js';
9
+ export * from './constants.js';
10
+ export * from './hooks/index.js';
11
+ export * as wasm from './wasm.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Iris Wallet SDK
3
+ * TypeScript SDK for interacting with Iris wallet extension
4
+ */
5
+ export * from './types.js';
6
+ export * from './provider.js';
7
+ export * from './transaction.js';
8
+ export * from './errors.js';
9
+ export * from './constants.js';
10
+ export * from './hooks/index.js';
11
+ export * as wasm from './wasm.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC"}