@ada-anvil/weld-plugin-hodei 0.0.1-alpha.2 → 0.0.1
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 +40 -1
- package/cdn.min.js +23 -0
- package/lib.cjs +1 -0
- package/lib.d.ts +31 -2
- package/lib.js +29 -7
- package/package.json +11 -7
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
1
|
# Weld Hodei Plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is a plugin for [Weld](https://github.com/cardano-forge/weld) to integrate with the [Hodei client](https://github.com/cardano-forge/hodei-client).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ada-anvil/weld-plugin-hodei @ada-anvil/weld
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Vanilla JS
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { weld } from "@ada-anvil/weld";
|
|
17
|
+
import { builtinPlugins } from "@ada-anvil/weld/plugins";
|
|
18
|
+
import { hodeiPlugin } from "@ada-anvil/weld-plugin-hodei";
|
|
19
|
+
|
|
20
|
+
weld.config.update({
|
|
21
|
+
plugins: [...builtinPlugins, hodeiPlugin(config)],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
weld.init();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### React
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { weld } from "@ada-anvil/weld";
|
|
31
|
+
import { builtinPlugins } from "@ada-anvil/weld/plugins";
|
|
32
|
+
import { hodeiPlugin } from "@ada-anvil/weld-plugin-hodei";
|
|
33
|
+
|
|
34
|
+
export const App = ({ children }) => {
|
|
35
|
+
return (
|
|
36
|
+
<WeldProvider plugins={[...builtinPlugins, hodeiPlugin(config)]}>
|
|
37
|
+
{children}
|
|
38
|
+
</WeldProvider>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
package/cdn.min.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var HodeiPlugin=(function(f,w){"use strict";async function A(e){const{baseUrl:t,apiKey:n}=e.config.anvil[e.network],o=new URL(`${t}/wallets/utxos`);return o.searchParams.set("address",e.address),o.searchParams.set("includeMempool","true"),(await fetch(o,{headers:{"x-api-key":n}})).json()}async function U(e){const{baseUrl:t,apiKey:n}=e.config.anvil[e.network],o=new URL(`${t}/wallets/balance`);return o.searchParams.set("address",e.address),(await fetch(o,{headers:{"x-api-key":n}})).json()}async function P(e){const{baseUrl:t,apiKey:n}=e.config.anvil[e.network];return(await fetch(`${t}/transactions/submit`,{method:"POST",headers:{"x-api-key":n,"content-type":"application/json"},body:JSON.stringify({transaction:e.transaction,signatures:e.signature?[e.signature]:[]})})).json()}const y="hodei-token";function k(){return localStorage.getItem(y)??void 0}function $(e){localStorage.setItem(y,e)}function E(){localStorage.removeItem(y)}function b(){let e="pending",t=()=>{},n=()=>{};const o=new Promise((u,c)=>{t=d=>{e="resolved",u(d)},n=d=>{e="rejected",c(d)}});return{status:e,promise:o,resolve:t,reject:n}}function g(e){if(e){if((e instanceof Error||_(e,"message"))&&typeof e.message=="string"&&e.message.length>0)return e.message;if(_(e,"data")&&_(e.data,"message")&&typeof e.data.message=="string"&&e.data.message.length>0)return e.data.message;if(typeof e=="string"&&e.length>0)return e}}function _(e,t){return typeof e=="object"&&e!==null&&t in e}class T{_config;_onStateChange;_debug;_connectPromise;_connection;constructor(t){this._config=t.config,this._onStateChange=t.onStateChange,this._debug=t.config?.debug??!1}setDebug(t){this._debug=t}debugLog(...t){if(!this._debug)return;let n="[HODEI]";this.connection&&(n+=` (${this.connection.id})`),console.log(n,...t)}get connection(){return this._connection}isConnected(){return this.connection?.state.status==="paired"||this.connection?.state.status==="pairing"}async connect(){if(this._connectPromise)return this._connectPromise;if(this.isConnected())return this.connection.state;this._connectPromise=this._connect();try{return await this._connectPromise}finally{this._connectPromise=void 0}}disconnect(){this._connection?.ws.close(1e3,"disconnected"),this._connection=void 0}unlink(){this.send({type:"client.session_unlinked",payload:{}})}getState(){return this.connection?.state}async _connect(){this.disconnect();const t=this._config.bridge.baseUrl.replace("http","ws"),n=new URL(`${t}/client/ws`),o=await this._getToken();o&&n.searchParams.set("token",o);const u=(this.connection?.id??0)+1,c=new WebSocket(n),d=new AbortController,i=b();this.debugLog("connecting"),c.addEventListener("message",r=>{try{const s=JSON.parse(r.data);I(s),this.debugLog("received connection message"),i.resolve(s.payload)}catch(s){i.reject(`Error parsing connection message ${r.data}: ${g(s)}`)}finally{d.abort()}},{signal:d.signal}),c.addEventListener("error",r=>{this.debugLog("received connection error"),i.reject(`Error connecting: ${g(r)}`),d.abort()},{signal:d.signal});try{const r=await i.promise;this.debugLog("connected"),$(r.token);const s={id:u,ws:c,state:r,controller:new AbortController};return this._connection=s,this._onStateChange(s.state),c.addEventListener("message",a=>{try{if(s.state.status==="error")throw new Error("Received message after error");if(s.state.status==="closed")throw new Error("Received message after closed");const l=JSON.parse(a.data);L(l),l.type==="client.wallet_updated"&&(this.debugLog("received wallet_updated message"),s.state={...l.payload,status:"paired",sessionId:s.state.sessionId,token:s.state.token},this._onStateChange(s.state))}catch(l){this.debugLog(`error parsing message ${a.data}: ${g(l)}`)}},{signal:s.controller.signal}),c.addEventListener("error",a=>{if(this._scheduleReconnect()){this.debugLog("scheduled reconnect after error");return}this.debugLog(`received error: ${g(a)}`),s.state={status:"error",error:g(a)},this._onStateChange(s.state),s.controller.abort()},{signal:s.controller.signal}),c.addEventListener("close",async a=>{if(a.code===4001&&(this.debugLog("session deleted"),E()),a.code!==1e3&&this._scheduleReconnect()){this.debugLog("scheduled reconnect after close");return}this.debugLog(`received close: ${a.code} ${a.reason}`),s.state={status:"closed",reason:a.reason,code:a.code},this._onStateChange(s.state),s.controller.abort()},{signal:s.controller.signal}),this._attempts=0,r}catch(r){throw c.close(void 0,`failed to connect: ${g(r)}`),r}}send(t){this.connection?.ws.send(JSON.stringify(t))}_attempts=0;_reconnectTimer;_scheduleReconnect(){this._reconnectTimer&&(this.debugLog("clearing reconnect timer"),clearTimeout(this._reconnectTimer)),this._attempts=Math.min(this._attempts+1,5);const t=2**this._attempts*1e3;this.debugLog(`reconnecting in ${t/1e3}s`);const n=setTimeout(()=>{if(this._reconnectTimer!==n){this.debugLog("reconnect timer cleared. ignoring");return}this.debugLog("reconnecting"),this._reconnectTimer=void 0,this._connect().catch(()=>this._scheduleReconnect())},t);return this._reconnectTimer=n,!0}async _getToken(){const t=k();if(!t)return;const n=await C({config:this._config,token:t});if(this.debugLog(`checked token: ${n.valid?"valid":`invalid: ${n.reason}`}`),n.valid)return t;if(n.reason==="alreadyConnected")throw new Error("Already connected");n.reason==="notFound"&&E()}}async function C(e){const t=new URL(`${e.config.bridge.baseUrl}/client/check`),n=await fetch(t,{method:"POST",headers:{Authorization:`Bearer ${e.token}`}});return n.status===404?{valid:!1,reason:"notFound"}:n.status===409?{valid:!1,reason:"alreadyConnected"}:{valid:!0,token:e.token}}function h(e){return typeof e=="object"&&e!==null}function H(e){return h(e)&&(e.status==="pairing"||e.status==="paired")}function I(e){if(!h(e)||e.type!=="client.connected"||!H(e.payload))throw new Error("Invalid connected message")}const j=new Set(["client.wallet_updated","client.sig_req_accepted","client.sig_req_rejected"]);function L(e){if(!h(e)||typeof e.type!="string"||!j.has(e.type))throw new Error("Invalid incoming message")}function O(e){if(!h(e)||e.type!=="client.sig_req_accepted"&&e.type!=="client.sig_req_rejected")throw new Error("Invalid sig req response")}const q=new Set(["pairing","paired","closed","error"]);function D(e){return h(e)&&typeof e.status=="string"&&q.has(e.status)}function v(e,t){e.dispatchEvent(new CustomEvent("command",{detail:t}))}function S(e,t,n){const o=u=>{const c=R(u);c&&t(c)};return e.addEventListener("command",o,n),()=>{e.removeEventListener("command",o,n)}}function R(e){if(e instanceof CustomEvent)return W(e.detail)?e.detail:void 0}const z=new Set(["disconnecting","disconnected","unlinked","dialog_closed"]);function W(e){if(typeof e!="object"||e===null)return!1;const t=e;return typeof t.type!="string"?!1:z.has(t.type)?!0:t.type==="state_changed"&&D(t.payload)}const N={bridge:{baseUrl:"https://bridge.hodei.io/api/dev"},anvil:{mainnet:{baseUrl:"https://prod.api.ada-anvil.app/v2/services",apiKey:"mainnet_IIrhwohjiEAJ2LFOgI8p5F735xz4C6XsgH6KfzpC"},preprod:{baseUrl:"https://preprod.api.ada-anvil.app/v2/services",apiKey:"testnet_C301LOscFsUccwR4zCqEtTJvizEAUc3AaVhRDdcY"}},debug:!1,waitForPairing:!0,onError:({error:e})=>console.error("[HODEI] unhandled error:",e??"unknown"),onClose:({code:e,reason:t})=>console.error("[HODEI] unhandled closure:",e,t)},J={refused:1,failure:2};function M(e,t){return{code:J[e],info:g(t)??"unknown"}}const F={invalidRequest:-1,internalError:-2,refused:-3,accountChange:-4};function p(e,t){return{code:F[e],info:g(t)??"unknown"}}function K(e){if(!(typeof window>"u"))return window.cardano||(window.cardano={}),window.cardano.hodei||(window.cardano.hodei=B(e)),window.cardano.hodei}function B(e={}){const t={config:{...N,...e}},n=async o=>{await t.promise?.catch(()=>{}),o.status==="error"&&t.config.onError(o),o.status==="closed"&&t.config.onClose(o),o.status==="paired"&&t.config.onWalletUpdate?.({baseAddress:o.baseAddress,stakeAddress:o.stakeAddress,network:o.network}),t.resolved?t.resolved?.client.sendCommand({sender:"wallet",type:"state_changed",payload:o}):console.error("[HODEI] (state_changed)",o)};return{name:"hodei",icon:"https://raw.githubusercontent.com/cardano-forge/weld/main/images/wallets/hodei.png",apiVersion:"1",async enable(){if(t.resolved?.bridge.isConnected())return t.resolved.api;t.promise||(t.promise=V({config:t.config,onStateChange:n}));try{const o=await t.promise;return t.resolved=o,t.config.waitForPairing?await o.pairingPromise:o.pairingPromise.catch(()=>{}),o.api}finally{t.promise=void 0}},async isEnabled(){if(t.promise)try{return await t.promise,!0}catch{return!1}if(t.resolved)return t.resolved.bridge.isConnected();const o=k();if(!o)return!1;try{return(await C({config:t.config,token:o})).valid}catch{return!1}}}}async function V(e){const t=await X(),n=new T(e);await n.connect(),S(t.element,i=>{if(i.sender==="client")switch(i.type){case"dialog_closed":{n.getState()?.status==="pairing"&&n.disconnect();break}case"disconnected":{n.disconnect();break}case"unlinked":{n.unlink();break}default:{n.debugLog(`unhandled command received from client: ${JSON.stringify(i)}`);break}}},{signal:n.connection?.controller.signal});const o=()=>{const i=n.getState();if(i?.status!=="paired")throw p("refused",new Error("Wallet is not connected"));return i},u=async i=>{if(o(),!n.isConnected())throw p("refused",new Error("Wallet is not connected"));const r=new AbortController;n.connection.controller.signal.addEventListener("abort",()=>r.abort(),{signal:r.signal});const s=b();return n.connection.ws.addEventListener("message",a=>{try{const l=JSON.parse(a.data);O(l);const m=l;if(m.payload.requestId!==i.requestId)return;m.type==="client.sig_req_accepted"?s.resolve(m.payload.signature):s.reject(`Rejected by user: ${m.payload.reason}`),r.abort()}catch(l){n.debugLog(`error parsing message ${a.data}: ${g(l)}`)}},{signal:r.signal}),n.send({type:"client.sig_req_created",payload:i}),s.promise},c={getNetworkId:async()=>o().network==="mainnet"?1:0,getUtxos:async()=>{const i=o();try{return await A({config:e.config,network:i.network,address:i.baseAddress})}catch(r){throw p("internalError",r)}},getBalance:async()=>{const i=o();try{return await U({config:e.config,network:i.network,address:i.baseAddress})}catch(r){throw p("internalError",r)}},getUsedAddresses:async()=>[o().baseAddress],getUnusedAddresses:async()=>[],getChangeAddress:async()=>o().baseAddress,getRewardAddresses:async()=>[o().stakeAddress],signTx:async(i,r=!1)=>u({requestId:crypto.randomUUID(),tx:i,partialSign:r}),signData:async(i,r)=>{const s=await u({requestId:crypto.randomUUID(),address:i,data:r}),[a,l]=s.split("::");if(!a||!l)throw p("internalError",new Error("Invalid signature"));return{signature:a,key:l}},submitTx:async i=>{const r=o();try{return(await P({config:e.config,network:r.network,transaction:i})).txHash}catch(s){throw M("failure",s)}},disconnect:async()=>{t.sendCommand({sender:"wallet",type:"disconnecting"})}},d=b();if(n.connection&&n.getState()?.status==="pairing"){const i=new AbortController;n.connection.controller.signal.addEventListener("abort",()=>{i.abort(),d.reject(new Error("Aborted"))},{signal:i.signal}),n.connection.ws.addEventListener("message",r=>{try{const s=JSON.parse(r.data);L(s),s.type==="client.wallet_updated"&&(d.resolve(),i.abort())}catch{}},{signal:i.signal})}else d.resolve();return{api:c,bridge:n,client:t,pairingPromise:d.promise}}async function X(){if(!customElements.get("hodei-client")){const t=await Promise.resolve().then(()=>ee);customElements.define("hodei-client",t.HodeiClient)}let e=document.querySelector("hodei-client")??void 0;if(!e){e=document.createElement("hodei-client");const t=b();e.addEventListener("mounted",()=>t.resolve(),{once:!0}),document.body.appendChild(e),await t.promise}return{element:e,sendCommand:t=>v(e,t)}}class x extends w.DefaultWalletHandler{async disconnect(){if("disconnect"in this.enabledApi&&typeof this.enabledApi.disconnect=="function")return this.enabledApi?.disconnect()}}function Y(e){return{key:"hodei",connector:w.getDefaultWalletConnector(x),initialize:w.runOnce(t=>K({debug:t.config.debug,...e,onError:o=>{t.config.debug&&console.error("[WELD] Hodei socket error, disconnecting.",o),e?.onError?.(o,t),t.wallet.disconnect()},onClose:o=>{t.config.debug&&console.error("[WELD] Hodei socket closed, disconnecting.",o),e?.onClose?.(o,t),t.wallet.disconnect()},onWalletUpdate:o=>{t.config.debug&&console.log("[WELD] Hodei wallet updated, updating state.",o),e?.onWalletUpdate?.(o,t),t.wallet.updateState()}})?(t.extensions.registerWallets([{supported:!0,key:"hodei",displayName:"Hodei",icon:"https://raw.githubusercontent.com/cardano-forge/weld/main/images/wallets/hodei.png",website:"https://github.com/cardano-forge/hodei-client",supportsTxChaining:!1}]),!0):!1)}}const G="*{box-sizing:border-box}:host{font-family:Roboto,Arial,Helvetica,sans-serif;pointer-events:auto}dialog{width:100%;max-width:300px;outline:none;border:none;padding:24px;background:transparent}dialog::backdrop{background:#00000052}article{padding:24px;border-radius:22px;display:flex;flex-direction:column;align-items:center;justify-content:center;flex:1;overflow:hidden;text-align:center;background:linear-gradient(to bottom right,#ebdee8,#fff7fa);color:#1e191e}h1{margin:12px 0 16px;font-size:20px;font-weight:400}p{margin:0;font-size:14px}h2{margin:0 0 24px;font-size:24px;font-weight:600;letter-spacing:.2em}img{width:75px;height:75px}button{--bg: #69548e;--fg: #ffffff;background:var(--bg);color:var(--fg);outline:none;border:none;height:32px;padding:0 12px;border-radius:24px;position:relative;overflow:hidden;transition:all .2s ease-in-out}button:hover{cursor:pointer;--bg: #746197;--fg: #ffffff}button.tonal{--bg: #e8dff8;--fg: #1e182b}button.tonal:hover{--bg: #d9cfe7;--fg: #1f182b}footer{margin-top:24px}@media(prefers-color-scheme:dark){article{background:linear-gradient(to bottom right,#362a36,#181215);color:#eadfe6}button{--bg: #d3bcfd;--fg: #37265c}button:hover{--bg: #c6b0f0;--fg: #37265c}button.tonal{--bg: #4b4358;--fg: #e8dff8}button.tonal:hover{--bg: #574f63;--fg: #e9def8}}",Q=`<dialog></dialog>
|
|
2
|
+
|
|
3
|
+
<template id="pairing">
|
|
4
|
+
<article>
|
|
5
|
+
<img src="https://ik.imagekit.io/pizzli/cforge/logo.png" alt="hodei" />
|
|
6
|
+
<h1>Pairing</h1>
|
|
7
|
+
<h2 class="pin"></h2>
|
|
8
|
+
<p>Enter this code on the Hodei app to pair your wallet</p>
|
|
9
|
+
</article>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<template id="disconnecting">
|
|
13
|
+
<article>
|
|
14
|
+
<img src="https://ik.imagekit.io/pizzli/cforge/logo.png" alt="hodei" />
|
|
15
|
+
<h1>Disconnecting</h1>
|
|
16
|
+
<p>Do you want to unlink your wallet from the Hodei app or disconnect only?</p>
|
|
17
|
+
<footer>
|
|
18
|
+
<button type="button" class="tonal" data-action="unlink">Unlink</button>
|
|
19
|
+
<button type="button" data-action="disconnect">Disconnect only</button>
|
|
20
|
+
</footer>
|
|
21
|
+
</article>
|
|
22
|
+
</template>
|
|
23
|
+
`;class Z extends HTMLElement{_state={status:"disconnected"};_shadow;_dialog;_unsub;_observer;constructor(){super(),this._shadow=this.attachShadow({mode:"open"}),this._shadow.innerHTML=`<style>${G}</style>${Q}`;const t=this._shadow.querySelector("dialog");if(t)this._dialog=t;else throw new Error("dialog not found");for(const n of["pointerdown","pointerup","click","mousedown","mouseup"])this.addEventListener(n,o=>o.stopPropagation());this._dialog.addEventListener("click",n=>{n.target===this._dialog&&this._dialog.close("backdrop")}),this._dialog.addEventListener("close",()=>{switch(this._state.status){case"pairing":v(this,{sender:"client",type:"dialog_closed"});break;case"disconnecting":this._dialog.returnValue==="backdrop"?this._state={status:"connected"}:v(this,{sender:"client",type:this._state.shouldUnlink?"unlinked":"disconnected"});break}})}connectedCallback(){this._unsub=S(this,n=>{if(n.sender==="wallet")switch(n.type){case"state_changed":switch(n.payload.status){case"paired":this._state={status:"connected"};break;case"pairing":this._state={status:"pairing",pin:n.payload.pin};break;default:this._state={status:"disconnected"};break}this._update();break;case"disconnecting":this._state.status==="connected"&&(this._state={status:"disconnecting",shouldUnlink:!1},this._update());break}});const t=this.parentElement;t&&(this._observer=new MutationObserver(()=>{t.lastElementChild!==this&&(t.removeChild(this),t.appendChild(this))}),this._observer.observe(t,{childList:!0})),this.dispatchEvent(new CustomEvent("mounted"))}disconnectedCallback(){this._unsub?.(),this._observer?.disconnect(),this.dispatchEvent(new CustomEvent("unmounted"))}_cloneTemplate(t){return this._shadow.querySelector(`#${t}`)?.content.cloneNode(!0)}_update(){const t=this._state;switch(t.status){case"pairing":{const n=this._cloneTemplate(t.status),o=n.querySelector(".pin");o&&(o.textContent=t.pin),this._dialog.replaceChildren(n),this._dialog.open||this._dialog.showModal();break}case"disconnecting":{const n=this._cloneTemplate(t.status);this._dialog.replaceChildren(n);for(const o of this._dialog.querySelectorAll("button"))o.addEventListener("click",()=>{t.shouldUnlink=o.dataset.action==="unlink",this._dialog.close("disconnect")});this._dialog.open||this._dialog.showModal();break}default:{this._dialog.open&&this._dialog.close("no-content");break}}}}const ee=Object.freeze(Object.defineProperty({__proto__:null,HodeiClient:Z},Symbol.toStringTag,{value:"Module"}));return f.HodeiHandler=x,f.hodeiPlugin=Y,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"}),f})({},WeldCore);
|
package/lib.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@ada-anvil/hodei-client"),o=require("@ada-anvil/weld/core");class i extends o.DefaultWalletHandler{async disconnect(){if("disconnect"in this.enabledApi&&typeof this.enabledApi.disconnect=="function")return this.enabledApi?.disconnect()}}function s(t){return{key:"hodei",connector:o.getDefaultWalletConnector(i),initialize:o.runOnce(e=>r.initialize({debug:e.config.debug,...t,onError:n=>{e.config.debug&&console.error("[WELD] Hodei socket error, disconnecting.",n),t?.onError?.(n,e),e.wallet.disconnect()},onClose:n=>{e.config.debug&&console.error("[WELD] Hodei socket closed, disconnecting.",n),t?.onClose?.(n,e),e.wallet.disconnect()},onWalletUpdate:n=>{e.config.debug&&console.log("[WELD] Hodei wallet updated, updating state.",n),t?.onWalletUpdate?.(n,e),e.wallet.updateState()}})?(e.extensions.registerWallets([{supported:!0,key:"hodei",displayName:"Hodei",icon:"https://raw.githubusercontent.com/cardano-forge/weld/main/images/wallets/hodei.png",website:"https://github.com/cardano-forge/hodei-client",supportsTxChaining:!1}]),!0):!1)}}exports.HodeiHandler=i;exports.hodeiPlugin=s;
|
package/lib.d.ts
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DefaultWalletHandler } from '@ada-anvil/weld/core';
|
|
2
|
+
import { WeldInstance } from '@ada-anvil/weld';
|
|
2
3
|
import { WeldPlugin } from '@ada-anvil/weld/plugins';
|
|
3
4
|
|
|
4
|
-
export declare
|
|
5
|
+
export declare class HodeiHandler extends DefaultWalletHandler {
|
|
6
|
+
disconnect(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare function hodeiPlugin(config?: Partial<HodeiPluginConfig>): WeldPlugin;
|
|
10
|
+
|
|
11
|
+
export declare type HodeiPluginConfig = {
|
|
12
|
+
bridge: {
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
};
|
|
15
|
+
anvil: Record<"mainnet" | "preprod", {
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
apiKey: string;
|
|
18
|
+
}>;
|
|
19
|
+
debug: boolean;
|
|
20
|
+
waitForPairing: boolean;
|
|
21
|
+
onError(data: {
|
|
22
|
+
error?: string;
|
|
23
|
+
}, weld: WeldInstance): void;
|
|
24
|
+
onClose(data: {
|
|
25
|
+
code: number;
|
|
26
|
+
reason: string;
|
|
27
|
+
}, weld: WeldInstance): void;
|
|
28
|
+
onWalletUpdate(wallet: {
|
|
29
|
+
baseAddress: string;
|
|
30
|
+
stakeAddress: string;
|
|
31
|
+
network: "mainnet" | "preprod";
|
|
32
|
+
}, weld: WeldInstance): void;
|
|
33
|
+
};
|
|
5
34
|
|
|
6
35
|
export { }
|
package/lib.js
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
|
-
import { initialize as
|
|
2
|
-
import {
|
|
3
|
-
class c extends
|
|
1
|
+
import { initialize as t } from "@ada-anvil/hodei-client";
|
|
2
|
+
import { DefaultWalletHandler as i, runOnce as r, getDefaultWalletConnector as s } from "@ada-anvil/weld/core";
|
|
3
|
+
class c extends i {
|
|
4
4
|
async disconnect() {
|
|
5
5
|
if ("disconnect" in this.enabledApi && typeof this.enabledApi.disconnect == "function")
|
|
6
6
|
return this.enabledApi?.disconnect();
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function u(o) {
|
|
10
10
|
return {
|
|
11
11
|
key: "hodei",
|
|
12
|
-
connector:
|
|
13
|
-
initialize:
|
|
12
|
+
connector: s(c),
|
|
13
|
+
initialize: r((e) => t({
|
|
14
|
+
debug: e.config.debug,
|
|
15
|
+
...o,
|
|
16
|
+
onError: (n) => {
|
|
17
|
+
e.config.debug && console.error("[WELD] Hodei socket error, disconnecting.", n), o?.onError?.(n, e), e.wallet.disconnect();
|
|
18
|
+
},
|
|
19
|
+
onClose: (n) => {
|
|
20
|
+
e.config.debug && console.error("[WELD] Hodei socket closed, disconnecting.", n), o?.onClose?.(n, e), e.wallet.disconnect();
|
|
21
|
+
},
|
|
22
|
+
onWalletUpdate: (n) => {
|
|
23
|
+
e.config.debug && console.log("[WELD] Hodei wallet updated, updating state.", n), o?.onWalletUpdate?.(n, e), e.wallet.updateState();
|
|
24
|
+
}
|
|
25
|
+
}) ? (e.extensions.registerWallets([
|
|
26
|
+
{
|
|
27
|
+
supported: !0,
|
|
28
|
+
key: "hodei",
|
|
29
|
+
displayName: "Hodei",
|
|
30
|
+
icon: "https://raw.githubusercontent.com/cardano-forge/weld/main/images/wallets/hodei.png",
|
|
31
|
+
website: "https://github.com/cardano-forge/hodei-client",
|
|
32
|
+
supportsTxChaining: !1
|
|
33
|
+
}
|
|
34
|
+
]), !0) : !1)
|
|
14
35
|
};
|
|
15
36
|
}
|
|
16
37
|
export {
|
|
17
|
-
|
|
38
|
+
c as HodeiHandler,
|
|
39
|
+
u as hodeiPlugin
|
|
18
40
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ada-anvil/weld-plugin-hodei",
|
|
3
|
-
"version": "0.0.1
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"devDependencies": {
|
|
5
|
-
"@ada-anvil/weld": "^0.
|
|
5
|
+
"@ada-anvil/weld": "^0.7.0",
|
|
6
6
|
"@biomejs/biome": "2.4.4",
|
|
7
7
|
"@microsoft/api-extractor": "^7.57.4",
|
|
8
|
+
"@types/node": "^25.4.0",
|
|
8
9
|
"typescript": "~5.9.3",
|
|
9
10
|
"unplugin-dts": "^1.0.0-beta.6",
|
|
10
11
|
"vite": "^7.3.1",
|
|
@@ -12,7 +13,9 @@
|
|
|
12
13
|
},
|
|
13
14
|
"scripts": {
|
|
14
15
|
"dev": "vite",
|
|
15
|
-
"build": "
|
|
16
|
+
"build:client": "vite build --config ./vite.client.ts",
|
|
17
|
+
"build:cdn": "vite build --config ./vite.cdn.ts",
|
|
18
|
+
"build": "tsc && bun run build:client && bun run build:cdn",
|
|
16
19
|
"preview": "vite preview",
|
|
17
20
|
"check": "tsc --noEmit",
|
|
18
21
|
"lint": "biome check --write .",
|
|
@@ -22,21 +25,22 @@
|
|
|
22
25
|
},
|
|
23
26
|
"type": "module",
|
|
24
27
|
"peerDependencies": {
|
|
25
|
-
"@ada-anvil/weld": "
|
|
28
|
+
"@ada-anvil/weld": ">=0.7.0"
|
|
26
29
|
},
|
|
27
30
|
"dependencies": {
|
|
28
|
-
"@ada-anvil/hodei-client": "^0.0.
|
|
31
|
+
"@ada-anvil/hodei-client": "^0.0.2"
|
|
29
32
|
},
|
|
30
33
|
"files": [
|
|
31
34
|
"**"
|
|
32
35
|
],
|
|
33
|
-
"main": "./lib.
|
|
36
|
+
"main": "./lib.cjs",
|
|
34
37
|
"module": "./lib.js",
|
|
35
38
|
"types": "./lib.d.ts",
|
|
36
39
|
"exports": {
|
|
37
40
|
".": {
|
|
38
41
|
"types": "./lib.d.ts",
|
|
39
|
-
"import": "./lib.js"
|
|
42
|
+
"import": "./lib.js",
|
|
43
|
+
"require": "./lib.cjs"
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
}
|