@rango-dev/provider-noir-wallet 0.1.1-next.0

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/CHANGELOG.md ADDED
File without changes
@@ -0,0 +1,5 @@
1
+ import { ChangeAccountSubscriberBuilder } from '@hub3js/std/hooks';
2
+ import { type NoirWalletProvider } from '@noir-wallet/sdk';
3
+ import { type UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';
4
+ export declare const changeAccountSubscriberBuilder: () => ChangeAccountSubscriberBuilder<import("@noir-wallet/sdk").ZcashAddress | null, NoirWalletProvider, UtxoActions>;
5
+ //# sourceMappingURL=utxo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/builders/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,KAAK,kBAAkB,EAAqB,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,yCAAyC,CAAC;AAIjD,eAAO,MAAM,8BAA8B,uHA0B1C,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ProviderMetadata } from '@hub3js/core';
2
+ export declare const WALLET_ID = "noir-wallet";
3
+ export declare const info: ProviderMetadata;
4
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKrD,eAAO,MAAM,SAAS,gBAAgB,CAAC;AAEvC,eAAO,MAAM,IAAI,EAAE,gBA+BlB,CAAC"}
package/dist/mod.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const versions: () => readonly [readonly ["1.0.0", import("@hub3js/core").Provider<Record<"utxo", import("@rango-dev/wallets-core/namespaces/utxo").UtxoActions>>]];
2
+ export { versions };
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,QAAQ,qJAC8C,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,CAAC"}
package/dist/mod.js ADDED
@@ -0,0 +1,2 @@
1
+ var E=Object.defineProperty;var e=(t,o)=>E(t,"name",{value:o,configurable:!0});import{defineVersions as F}from"@hub3js/core/utils";import{ProviderBuilder as k}from"@hub3js/core";import{isNoirWalletInstalled as M}from"@noir-wallet/sdk";import{DefaultSignerFactory as v,TransactionType as z}from"rango-types";import{LegacyNetworks as I}from"@rango-dev/wallets-core/legacy";import{BigNumber as W}from"bignumber.js";import{SignerError as m,SignerErrorCode as l}from"rango-types";import{getNoirWallet as x}from"@noir-wallet/sdk";var n=e(()=>{let t=x();if(!t)throw new Error("Noir Wallet not installed");return t},"getInstanceOrThrow");var c=class{static{e(this,"CustomUtxoSigner")}async signMessage(o){return(await n().zcash.signMessage(o)).signature}async signAndSendTx(o){let{memo:r,recipientAddress:a,amount:p,decimals:S,blockChain:T}=o;if(T!==I.ZCASH)throw new Error(`You can not sign ${o.blockChain} using ZCash signer.`);if(r)throw new m(l.UNEXPECTED_BEHAVIOUR,"Noir Wallet can not attach a protocol memo (OP_RETURN) to a Zcash transaction.",void 0);let C=new W(p).shiftedBy(-S).toFixed();try{return{hash:await n().zcash.sendTransaction({to:a,amount:C,fundingSource:"transparent"})}}catch(i){throw typeof i=="string"?new m(l.UNEXPECTED_BEHAVIOUR,i,void 0):new m(l.SEND_TX_ERROR,void 0,i)}}};async function u(){let t=new v;return t.registerSigner(z.TRANSFER,new c),t}e(u,"getSigners");var s="noir-wallet",d={name:"Noir Wallet",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/noir-wallet/icon.svg",extensions:{chrome:"https://chromewebstore.google.com/detail/noir-wallet/mfoghjbpfanobmnoemoepenjjcmfpmdn",homepage:"https://www.zknoir.com/"},properties:[{name:"namespaces",value:{selection:"multiple",data:[{label:"Zcash",value:"UTXO",id:"ZCASH",getSupportedChains:t=>t.filter(o=>o.name==="ZCASH")}]}},{name:"signers",value:{getSigners:async()=>u()}}]};import{ActionBuilder as B,NamespaceBuilder as U}from"@hub3js/core";import*as A from"@hub3js/std/builders";import{standardizeAndThrowError as Z}from"@hub3js/std/operators";import{builders as D,CAIP_ZCASH_CHAIN_ID as g,utils as h}from"@rango-dev/wallets-core/namespaces/utxo";import{ChangeAccountSubscriberBuilder as P}from"@hub3js/std/hooks";import"@noir-wallet/sdk";import{CAIP_ZCASH_CHAIN_ID as N,utils as _}from"@rango-dev/wallets-core/namespaces/utxo";var f=e(()=>new P().getInstance(n).onSwitchAccount((t,o)=>{if(!t.payload?.transparent){o.action("disconnect"),t.preventDefault();return}}).format(async(t,o)=>_.formatAccountsToCAIP(o?.transparent?[o.transparent]:[],N)).addEventListener((t,o)=>{t.zcash.on("accountsChanged",o)}).removeEventListener((t,o)=>{t.zcash.removeListener("accountsChanged",o)}),"changeAccountSubscriberBuilder");var[L,w]=f().build(),O=D.connect().action(async function(){let o=n().zcash,r=await o.getAccounts();if(!r){let a=await o.connect();return h.formatAccountsToCAIP([a.transparent],g)}return h.formatAccountsToCAIP([r.transparent],g)}).before(L).or(w).or(Z).build(),H=new B("canEagerConnect").action(async()=>{try{return!!await n().zcash.getAccounts()}catch{return!1}}).build(),R=A.disconnect().before(()=>{try{n().zcash.disconnect()}catch{}}).after(w).build(),b=new U("UTXO",s).action(O).action(R).action(H).build();var y=e(()=>new k(s).init(function(t){let[,o]=t.state();M()&&(o("installed",!0),console.debug("[noir-wallet] instance detected.",t))}).config("metadata",d).add("utxo",b).build(),"buildProvider");var zt=e(()=>F().version("1.0.0",y()).build(),"versions");export{zt as versions};
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/mod.ts", "../src/provider.ts", "../src/signer.ts", "../src/signers/signer.ts", "../src/utils.ts", "../src/constants.ts", "../src/namespaces/utxo.ts", "../src/builders/utxo.ts"],
4
+ "sourcesContent": ["import { defineVersions } from '@hub3js/core/utils';\n\nimport { buildProvider } from './provider.js';\n\nconst versions = () =>\n defineVersions().version('1.0.0', buildProvider()).build();\n\nexport { versions };\n", "import { ProviderBuilder } from '@hub3js/core';\nimport { isNoirWalletInstalled } from '@noir-wallet/sdk';\n\nimport { info, WALLET_ID } from './constants.js';\nimport { namespace as utxo } from './namespaces/utxo.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n if (isNoirWalletInstalled()) {\n setState('installed', true);\n console.debug('[noir-wallet] instance detected.', context);\n }\n })\n .config('metadata', info)\n .add('utxo', utxo)\n .build();\n\nexport { buildProvider };\n", "import type { SignerFactory } from 'rango-types';\n\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nimport { CustomUtxoSigner } from './signers/signer.js';\n\nexport default async function getSigners(): Promise<SignerFactory> {\n const signers = new DefaultSignerFactory();\n\n signers.registerSigner(TxType.TRANSFER, new CustomUtxoSigner());\n return signers;\n}\n", "import type { Transfer } from 'rango-types/mainApi';\n\nimport { LegacyNetworks } from '@rango-dev/wallets-core/legacy';\nimport { BigNumber } from 'bignumber.js';\nimport { type GenericSigner, SignerError, SignerErrorCode } from 'rango-types';\n\nimport { getInstanceOrThrow } from '../utils.js';\n\nexport class CustomUtxoSigner implements GenericSigner<Transfer> {\n async signMessage(msg: string): Promise<string> {\n const noirWallet = getInstanceOrThrow();\n const zcash = noirWallet.zcash;\n\n const result = await zcash.signMessage(msg);\n return result.signature;\n }\n\n async signAndSendTx(tx: Transfer): Promise<{ hash: string }> {\n const { memo, recipientAddress, amount, decimals, blockChain } = tx;\n\n if (blockChain !== LegacyNetworks.ZCASH) {\n throw new Error(`You can not sign ${tx.blockChain} using ZCash signer.`);\n }\n\n if (memo) {\n throw new SignerError(\n SignerErrorCode.UNEXPECTED_BEHAVIOUR,\n 'Noir Wallet can not attach a protocol memo (OP_RETURN) to a Zcash transaction.',\n undefined\n );\n }\n\n /*\n * Rango provides `amount` in the asset's smallest unit (zatoshis), but the\n * Noir Wallet expects a decimal ZEC string. Shift by `-decimals` to convert\n * (e.g. \"1000000\" zatoshis -> \"0.01\" ZEC).\n */\n const amountInZec = new BigNumber(amount).shiftedBy(-decimals).toFixed();\n\n try {\n const noirWallet = getInstanceOrThrow();\n const zcash = noirWallet.zcash;\n\n const txid = await zcash.sendTransaction({\n to: recipientAddress,\n amount: amountInZec,\n fundingSource: 'transparent',\n });\n return { hash: txid };\n } catch (error) {\n if (typeof error === 'string') {\n throw new SignerError(\n SignerErrorCode.UNEXPECTED_BEHAVIOUR,\n error,\n undefined\n );\n }\n throw new SignerError(SignerErrorCode.SEND_TX_ERROR, undefined, error);\n }\n }\n}\n", "import { getNoirWallet } from '@noir-wallet/sdk';\n\nexport const getInstanceOrThrow = () => {\n const noirWallet = getNoirWallet();\n if (!noirWallet) {\n throw new Error('Noir Wallet not installed');\n }\n return noirWallet;\n};\n", "import type { ProviderMetadata } from '@hub3js/core';\nimport type { BlockchainMeta } from 'rango-types';\n\nimport getSigners from './signer.js';\n\nexport const WALLET_ID = 'noir-wallet';\n\nexport const info: ProviderMetadata = {\n name: 'Noir Wallet',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/noir-wallet/icon.svg',\n extensions: {\n chrome:\n 'https://chromewebstore.google.com/detail/noir-wallet/mfoghjbpfanobmnoemoepenjjcmfpmdn',\n homepage: 'https://www.zknoir.com/',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'multiple',\n data: [\n {\n label: 'Zcash',\n value: 'UTXO',\n id: 'ZCASH',\n getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n allBlockchains.filter(\n (blockchain) => blockchain.name === 'ZCASH'\n ),\n },\n ],\n },\n },\n {\n name: 'signers',\n value: { getSigners: async () => getSigners() },\n },\n ],\n};\n", "import type { UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport { ActionBuilder, NamespaceBuilder } from '@hub3js/core';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\nimport {\n builders,\n CAIP_ZCASH_CHAIN_ID,\n utils,\n} from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport { changeAccountSubscriberBuilder } from '../builders/utxo.js';\nimport { WALLET_ID } from '../constants.js';\nimport { getInstanceOrThrow } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n changeAccountSubscriberBuilder().build();\n\nconst connect = builders\n .connect()\n .action(async function () {\n const noirWallet = getInstanceOrThrow();\n const zcash = noirWallet.zcash;\n\n // Check existing connection (silent, no popup)\n const accounts = await zcash.getAccounts();\n\n // Connect wallet if not connected (shows popup)\n if (!accounts) {\n const newAccounts = await zcash.connect();\n return utils.formatAccountsToCAIP(\n [newAccounts.transparent],\n CAIP_ZCASH_CHAIN_ID\n );\n }\n return utils.formatAccountsToCAIP(\n [accounts.transparent],\n CAIP_ZCASH_CHAIN_ID\n );\n })\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst canEagerConnect = new ActionBuilder<UtxoActions, 'canEagerConnect'>(\n 'canEagerConnect'\n)\n .action(async () => {\n try {\n const noirWallet = getInstanceOrThrow();\n const zcash = noirWallet.zcash;\n\n // Check existing connection (silent, no popup)\n const accounts = await zcash.getAccounts();\n\n return !!accounts;\n } catch {\n return false;\n }\n })\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<UtxoActions>()\n .before(() => {\n try {\n const noirWallet = getInstanceOrThrow();\n const zcash = noirWallet.zcash;\n void zcash.disconnect();\n } catch {\n // Ignore errors during disconnect\n }\n })\n .after(changeAccountCleanup)\n .build();\n\nexport const namespace = new NamespaceBuilder<UtxoActions>('UTXO', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .build();\n", "import { ChangeAccountSubscriberBuilder } from '@hub3js/std/hooks';\nimport { type NoirWalletProvider, type ZcashAccount } from '@noir-wallet/sdk';\nimport {\n CAIP_ZCASH_CHAIN_ID,\n utils,\n type UtxoActions,\n} from '@rango-dev/wallets-core/namespaces/utxo';\n\nimport { getInstanceOrThrow } from '../utils.js';\n\nexport const changeAccountSubscriberBuilder = () => {\n return new ChangeAccountSubscriberBuilder<\n ZcashAccount['addresses'] | null,\n NoirWalletProvider,\n UtxoActions\n >()\n .getInstance(getInstanceOrThrow)\n .onSwitchAccount((event, context) => {\n if (!event.payload?.transparent) {\n void context.action('disconnect');\n event.preventDefault();\n return;\n }\n })\n .format(async (_, payload) =>\n utils.formatAccountsToCAIP(\n payload?.transparent ? [payload.transparent] : [],\n CAIP_ZCASH_CHAIN_ID\n )\n )\n .addEventListener((instance, callback) => {\n instance.zcash.on('accountsChanged', callback);\n })\n .removeEventListener((instance, callback) => {\n instance.zcash.removeListener('accountsChanged', callback);\n });\n};\n"],
5
+ "mappings": "+EAAA,OAAS,kBAAAA,MAAsB,qBCA/B,OAAS,mBAAAC,MAAuB,eAChC,OAAS,yBAAAC,MAA6B,mBCCtC,OAAS,wBAAAC,EAAsB,mBAAmBC,MAAc,cCAhE,OAAS,kBAAAC,MAAsB,iCAC/B,OAAS,aAAAC,MAAiB,eAC1B,OAA6B,eAAAC,EAAa,mBAAAC,MAAuB,cCJjE,OAAS,iBAAAC,MAAqB,mBAEvB,IAAMC,EAAqBC,EAAA,IAAM,CACtC,IAAMC,EAAaC,EAAc,EACjC,GAAI,CAACD,EACH,MAAM,IAAI,MAAM,2BAA2B,EAE7C,OAAOA,CACT,EANkC,sBDM3B,IAAME,EAAN,KAA0D,CARjE,MAQiE,CAAAC,EAAA,yBAC/D,MAAM,YAAYC,EAA8B,CAK9C,OADe,MAHIC,EAAmB,EACb,MAEE,YAAYD,CAAG,GAC5B,SAChB,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,OAAO,IAAM,CACZ,GAAI,CACiBR,EAAmB,EACb,MACd,WAAW,CACxB,MAAQ,CAER,CACF,CAAC,EACA,MAAML,CAAoB,EAC1B,MAAM,EAEIc,EAAY,IAAIC,EAA8B,OAAQC,CAAS,EACzE,OAAOd,CAAO,EACd,OAAOW,CAAU,EACjB,OAAOF,CAAe,EACtB,MAAM,EL3ET,IAAMM,EAAgBC,EAAA,IACpB,IAAIC,EAAgBC,CAAS,EAC1B,KAAK,SAAUC,EAAS,CACvB,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EAC/BE,EAAsB,IACxBD,EAAS,YAAa,EAAI,EAC1B,QAAQ,MAAM,mCAAoCD,CAAO,EAE7D,CAAC,EACA,OAAO,WAAYG,CAAI,EACvB,IAAI,OAAQC,CAAI,EAChB,MAAM,EAXW,iBDFtB,IAAMC,GAAWC,EAAA,IACfC,EAAe,EAAE,QAAQ,QAASC,EAAc,CAAC,EAAE,MAAM,EAD1C",
6
+ "names": ["defineVersions", "ProviderBuilder", "isNoirWalletInstalled", "DefaultSignerFactory", "TxType", "LegacyNetworks", "BigNumber", "SignerError", "SignerErrorCode", "getNoirWallet", "getInstanceOrThrow", "__name", "noirWallet", "getNoirWallet", "CustomUtxoSigner", "__name", "msg", "getInstanceOrThrow", "tx", "memo", "recipientAddress", "amount", "decimals", "blockChain", "LegacyNetworks", "SignerError", "SignerErrorCode", "amountInZec", "BigNumber", "error", "getSigners", "signers", "DefaultSignerFactory", "TxType", "CustomUtxoSigner", "__name", "WALLET_ID", "info", "allBlockchains", "blockchain", "getSigners", "ActionBuilder", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "builders", "CAIP_ZCASH_CHAIN_ID", "utils", "ChangeAccountSubscriberBuilder", "CAIP_ZCASH_CHAIN_ID", "utils", "changeAccountSubscriberBuilder", "__name", "ChangeAccountSubscriberBuilder", "getInstanceOrThrow", "event", "context", "_", "payload", "utils", "CAIP_ZCASH_CHAIN_ID", "instance", "callback", "changeAccountSubscriber", "changeAccountCleanup", "changeAccountSubscriberBuilder", "connect", "builders", "zcash", "getInstanceOrThrow", "accounts", "newAccounts", "utils", "CAIP_ZCASH_CHAIN_ID", "standardizeAndThrowError", "canEagerConnect", "ActionBuilder", "disconnect", "namespace", "NamespaceBuilder", "WALLET_ID", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "isNoirWalletInstalled", "info", "namespace", "versions", "__name", "defineVersions", "buildProvider"]
7
+ }
@@ -0,0 +1,3 @@
1
+ import type { UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';
2
+ export declare const namespace: import("@hub3js/core").ProxiedNamespace<UtxoActions>;
3
+ //# sourceMappingURL=utxo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src/namespaces/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AA6E3E,eAAO,MAAM,SAAS,sDAIZ,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const buildProvider: () => import("@hub3js/core").Provider<Record<"utxo", import("@rango-dev/wallets-core/namespaces/utxo").UtxoActions>>;
2
+ export { buildProvider };
3
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,aAAa,sHAWP,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { SignerFactory } from 'rango-types';
2
+ export default function getSigners(): Promise<SignerFactory>;
3
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMjD,wBAA8B,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC,CAKjE"}
@@ -0,0 +1,9 @@
1
+ import type { Transfer } from 'rango-types/mainApi';
2
+ import { type GenericSigner } from 'rango-types';
3
+ export declare class CustomUtxoSigner implements GenericSigner<Transfer> {
4
+ signMessage(msg: string): Promise<string>;
5
+ signAndSendTx(tx: Transfer): Promise<{
6
+ hash: string;
7
+ }>;
8
+ }
9
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signers/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIpD,OAAO,EAAE,KAAK,aAAa,EAAgC,MAAM,aAAa,CAAC;AAI/E,qBAAa,gBAAiB,YAAW,aAAa,CAAC,QAAQ,CAAC;IACxD,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQzC,aAAa,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CA2C7D"}
@@ -0,0 +1,2 @@
1
+ export declare const getInstanceOrThrow: () => import("@noir-wallet/sdk").NoirWalletProvider;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,qDAM9B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@rango-dev/provider-noir-wallet",
3
+ "version": "0.1.1-next.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "source": "./src/mod.ts",
7
+ "main": "./dist/mod.js",
8
+ "exports": {
9
+ ".": "./dist/mod.js"
10
+ },
11
+ "typings": "dist/mod.d.ts",
12
+ "files": [
13
+ "dist",
14
+ "src"
15
+ ],
16
+ "scripts": {
17
+ "build": "yarn run rangutopia library build",
18
+ "ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
19
+ "clean": "rimraf dist",
20
+ "format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
21
+ "lint": "eslint \"**/*.{ts,tsx}\""
22
+ },
23
+ "dependencies": {
24
+ "@hub3js/core": "^0.61.0",
25
+ "@hub3js/std": "^0.2.0",
26
+ "@noir-wallet/sdk": "^0.1.9",
27
+ "@rango-dev/wallets-core": "^0.60.1-next.3",
28
+ "bignumber.js": "^9.1.1",
29
+ "rango-types": "^0.5.0"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }
package/readme.md ADDED
@@ -0,0 +1,28 @@
1
+ # Noir Wallet Provider
2
+
3
+ Noir Wallet integration for hub.
4
+ [Homepage](https://www.zknoir.com/) | [Docs](https://github.com/NoirWallet/noir-wallet-sdk)
5
+
6
+ More about implementation status can be found [here](../readme.md).
7
+
8
+ ## Implementation notes/limitation
9
+
10
+ ### Group
11
+
12
+ #### ⚠️ UTXO
13
+
14
+ Only supports Zcash.
15
+
16
+ ### Feature
17
+
18
+ #### ⚠️ Sign transaction
19
+
20
+ It only supports Zcash transparent transactions.
21
+
22
+ #### ⚠️ Switch Account
23
+
24
+ The wallet emits an empty array as switch account event when it gets locked and the namespace gets disconnected.
25
+
26
+ ---
27
+
28
+ More wallet information can be found in [readme.md](../readme.md).
@@ -0,0 +1,37 @@
1
+ import { ChangeAccountSubscriberBuilder } from '@hub3js/std/hooks';
2
+ import { type NoirWalletProvider, type ZcashAccount } from '@noir-wallet/sdk';
3
+ import {
4
+ CAIP_ZCASH_CHAIN_ID,
5
+ utils,
6
+ type UtxoActions,
7
+ } from '@rango-dev/wallets-core/namespaces/utxo';
8
+
9
+ import { getInstanceOrThrow } from '../utils.js';
10
+
11
+ export const changeAccountSubscriberBuilder = () => {
12
+ return new ChangeAccountSubscriberBuilder<
13
+ ZcashAccount['addresses'] | null,
14
+ NoirWalletProvider,
15
+ UtxoActions
16
+ >()
17
+ .getInstance(getInstanceOrThrow)
18
+ .onSwitchAccount((event, context) => {
19
+ if (!event.payload?.transparent) {
20
+ void context.action('disconnect');
21
+ event.preventDefault();
22
+ return;
23
+ }
24
+ })
25
+ .format(async (_, payload) =>
26
+ utils.formatAccountsToCAIP(
27
+ payload?.transparent ? [payload.transparent] : [],
28
+ CAIP_ZCASH_CHAIN_ID
29
+ )
30
+ )
31
+ .addEventListener((instance, callback) => {
32
+ instance.zcash.on('accountsChanged', callback);
33
+ })
34
+ .removeEventListener((instance, callback) => {
35
+ instance.zcash.removeListener('accountsChanged', callback);
36
+ });
37
+ };
@@ -0,0 +1,39 @@
1
+ import type { ProviderMetadata } from '@hub3js/core';
2
+ import type { BlockchainMeta } from 'rango-types';
3
+
4
+ import getSigners from './signer.js';
5
+
6
+ export const WALLET_ID = 'noir-wallet';
7
+
8
+ export const info: ProviderMetadata = {
9
+ name: 'Noir Wallet',
10
+ icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/noir-wallet/icon.svg',
11
+ extensions: {
12
+ chrome:
13
+ 'https://chromewebstore.google.com/detail/noir-wallet/mfoghjbpfanobmnoemoepenjjcmfpmdn',
14
+ homepage: 'https://www.zknoir.com/',
15
+ },
16
+ properties: [
17
+ {
18
+ name: 'namespaces',
19
+ value: {
20
+ selection: 'multiple',
21
+ data: [
22
+ {
23
+ label: 'Zcash',
24
+ value: 'UTXO',
25
+ id: 'ZCASH',
26
+ getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
27
+ allBlockchains.filter(
28
+ (blockchain) => blockchain.name === 'ZCASH'
29
+ ),
30
+ },
31
+ ],
32
+ },
33
+ },
34
+ {
35
+ name: 'signers',
36
+ value: { getSigners: async () => getSigners() },
37
+ },
38
+ ],
39
+ };
package/src/mod.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { defineVersions } from '@hub3js/core/utils';
2
+
3
+ import { buildProvider } from './provider.js';
4
+
5
+ const versions = () =>
6
+ defineVersions().version('1.0.0', buildProvider()).build();
7
+
8
+ export { versions };
@@ -0,0 +1,82 @@
1
+ import type { UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';
2
+
3
+ import { ActionBuilder, NamespaceBuilder } from '@hub3js/core';
4
+ import * as commonBuilders from '@hub3js/std/builders';
5
+ import { standardizeAndThrowError } from '@hub3js/std/operators';
6
+ import {
7
+ builders,
8
+ CAIP_ZCASH_CHAIN_ID,
9
+ utils,
10
+ } from '@rango-dev/wallets-core/namespaces/utxo';
11
+
12
+ import { changeAccountSubscriberBuilder } from '../builders/utxo.js';
13
+ import { WALLET_ID } from '../constants.js';
14
+ import { getInstanceOrThrow } from '../utils.js';
15
+
16
+ const [changeAccountSubscriber, changeAccountCleanup] =
17
+ changeAccountSubscriberBuilder().build();
18
+
19
+ const connect = builders
20
+ .connect()
21
+ .action(async function () {
22
+ const noirWallet = getInstanceOrThrow();
23
+ const zcash = noirWallet.zcash;
24
+
25
+ // Check existing connection (silent, no popup)
26
+ const accounts = await zcash.getAccounts();
27
+
28
+ // Connect wallet if not connected (shows popup)
29
+ if (!accounts) {
30
+ const newAccounts = await zcash.connect();
31
+ return utils.formatAccountsToCAIP(
32
+ [newAccounts.transparent],
33
+ CAIP_ZCASH_CHAIN_ID
34
+ );
35
+ }
36
+ return utils.formatAccountsToCAIP(
37
+ [accounts.transparent],
38
+ CAIP_ZCASH_CHAIN_ID
39
+ );
40
+ })
41
+ .before(changeAccountSubscriber)
42
+ .or(changeAccountCleanup)
43
+ .or(standardizeAndThrowError)
44
+ .build();
45
+
46
+ const canEagerConnect = new ActionBuilder<UtxoActions, 'canEagerConnect'>(
47
+ 'canEagerConnect'
48
+ )
49
+ .action(async () => {
50
+ try {
51
+ const noirWallet = getInstanceOrThrow();
52
+ const zcash = noirWallet.zcash;
53
+
54
+ // Check existing connection (silent, no popup)
55
+ const accounts = await zcash.getAccounts();
56
+
57
+ return !!accounts;
58
+ } catch {
59
+ return false;
60
+ }
61
+ })
62
+ .build();
63
+
64
+ const disconnect = commonBuilders
65
+ .disconnect<UtxoActions>()
66
+ .before(() => {
67
+ try {
68
+ const noirWallet = getInstanceOrThrow();
69
+ const zcash = noirWallet.zcash;
70
+ void zcash.disconnect();
71
+ } catch {
72
+ // Ignore errors during disconnect
73
+ }
74
+ })
75
+ .after(changeAccountCleanup)
76
+ .build();
77
+
78
+ export const namespace = new NamespaceBuilder<UtxoActions>('UTXO', WALLET_ID)
79
+ .action(connect)
80
+ .action(disconnect)
81
+ .action(canEagerConnect)
82
+ .build();
@@ -0,0 +1,20 @@
1
+ import { ProviderBuilder } from '@hub3js/core';
2
+ import { isNoirWalletInstalled } from '@noir-wallet/sdk';
3
+
4
+ import { info, WALLET_ID } from './constants.js';
5
+ import { namespace as utxo } from './namespaces/utxo.js';
6
+
7
+ const buildProvider = () =>
8
+ new ProviderBuilder(WALLET_ID)
9
+ .init(function (context) {
10
+ const [, setState] = context.state();
11
+ if (isNoirWalletInstalled()) {
12
+ setState('installed', true);
13
+ console.debug('[noir-wallet] instance detected.', context);
14
+ }
15
+ })
16
+ .config('metadata', info)
17
+ .add('utxo', utxo)
18
+ .build();
19
+
20
+ export { buildProvider };
package/src/signer.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { SignerFactory } from 'rango-types';
2
+
3
+ import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';
4
+
5
+ import { CustomUtxoSigner } from './signers/signer.js';
6
+
7
+ export default async function getSigners(): Promise<SignerFactory> {
8
+ const signers = new DefaultSignerFactory();
9
+
10
+ signers.registerSigner(TxType.TRANSFER, new CustomUtxoSigner());
11
+ return signers;
12
+ }
@@ -0,0 +1,61 @@
1
+ import type { Transfer } from 'rango-types/mainApi';
2
+
3
+ import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
4
+ import { BigNumber } from 'bignumber.js';
5
+ import { type GenericSigner, SignerError, SignerErrorCode } from 'rango-types';
6
+
7
+ import { getInstanceOrThrow } from '../utils.js';
8
+
9
+ export class CustomUtxoSigner implements GenericSigner<Transfer> {
10
+ async signMessage(msg: string): Promise<string> {
11
+ const noirWallet = getInstanceOrThrow();
12
+ const zcash = noirWallet.zcash;
13
+
14
+ const result = await zcash.signMessage(msg);
15
+ return result.signature;
16
+ }
17
+
18
+ async signAndSendTx(tx: Transfer): Promise<{ hash: string }> {
19
+ const { memo, recipientAddress, amount, decimals, blockChain } = tx;
20
+
21
+ if (blockChain !== LegacyNetworks.ZCASH) {
22
+ throw new Error(`You can not sign ${tx.blockChain} using ZCash signer.`);
23
+ }
24
+
25
+ if (memo) {
26
+ throw new SignerError(
27
+ SignerErrorCode.UNEXPECTED_BEHAVIOUR,
28
+ 'Noir Wallet can not attach a protocol memo (OP_RETURN) to a Zcash transaction.',
29
+ undefined
30
+ );
31
+ }
32
+
33
+ /*
34
+ * Rango provides `amount` in the asset's smallest unit (zatoshis), but the
35
+ * Noir Wallet expects a decimal ZEC string. Shift by `-decimals` to convert
36
+ * (e.g. "1000000" zatoshis -> "0.01" ZEC).
37
+ */
38
+ const amountInZec = new BigNumber(amount).shiftedBy(-decimals).toFixed();
39
+
40
+ try {
41
+ const noirWallet = getInstanceOrThrow();
42
+ const zcash = noirWallet.zcash;
43
+
44
+ const txid = await zcash.sendTransaction({
45
+ to: recipientAddress,
46
+ amount: amountInZec,
47
+ fundingSource: 'transparent',
48
+ });
49
+ return { hash: txid };
50
+ } catch (error) {
51
+ if (typeof error === 'string') {
52
+ throw new SignerError(
53
+ SignerErrorCode.UNEXPECTED_BEHAVIOUR,
54
+ error,
55
+ undefined
56
+ );
57
+ }
58
+ throw new SignerError(SignerErrorCode.SEND_TX_ERROR, undefined, error);
59
+ }
60
+ }
61
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { getNoirWallet } from '@noir-wallet/sdk';
2
+
3
+ export const getInstanceOrThrow = () => {
4
+ const noirWallet = getNoirWallet();
5
+ if (!noirWallet) {
6
+ throw new Error('Noir Wallet not installed');
7
+ }
8
+ return noirWallet;
9
+ };