@rango-dev/provider-freighter 0.0.0-experimental-82bcc5d9-20260608

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
@@ -0,0 +1,9 @@
1
+ # 0.2.0 (2026-05-31)
2
+
3
+
4
+ ### Features
5
+
6
+ * integrate freighter wallet ([8d39b94](https://github.com/rango-exchange/rango-client/commit/8d39b947e073ed16b2a4f09d1bd7e7b1e3df2047))
7
+
8
+
9
+
@@ -0,0 +1,7 @@
1
+ import type { ProviderMetadata } from '@hub3js/core';
2
+ export declare const WALLET_ID = "frighter";
3
+ export declare const HORIZON_URL = "https://horizon.stellar.org";
4
+ export declare const RPC_URL = "https://mainnet.sorobanrpc.com";
5
+ export declare const NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015";
6
+ export declare const metadata: ProviderMetadata;
7
+ //# 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;AAOrD,eAAO,MAAM,SAAS,aAAa,CAAC;AACpC,eAAO,MAAM,WAAW,gCAAgC,CAAC;AACzD,eAAO,MAAM,OAAO,mCAAmC,CAAC;AACxD,eAAO,MAAM,kBAAkB,mDACmB,CAAC;AAEnD,eAAO,MAAM,QAAQ,EAAE,gBAmCtB,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<"stellar", import("@rango-dev/wallets-core/namespaces/stellar").StellarActions>>]];
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,8JAC8C,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,CAAC"}
package/dist/mod.js ADDED
@@ -0,0 +1,2 @@
1
+ var R=Object.defineProperty;var o=(r,e)=>R(r,"name",{value:e,configurable:!0});var s=(r,e)=>()=>(r&&(e=r(r=0)),e);var W=(r,e)=>{for(var t in e)R(r,t,{get:e[t],enumerable:!0})};import{ChangeAccountSubscriberBuilder as F}from"@hub3js/std/hooks";import{utils as H}from"@rango-dev/wallets-core/namespaces/stellar";import{WatchWalletChanges as q}from"@stellar/freighter-api";function k(){return new F().getInstance(()=>new q(G)).format(async(r,e)=>[H.formatAddressToCAIP(e.address)]).addEventListener((r,e)=>{r.watch(e)}).onSwitchAccount((r,e)=>{r.payload.address||(e.action("disconnect"),r.preventDefault())}).removeEventListener(r=>{r.stop()}).build()}var G,E=s(()=>{"use strict";G=1e3;o(k,"changeAccountSubscriberBuilder")});import{ActionBuilder as j,NamespaceBuilder as z}from"@hub3js/core";import*as v from"@hub3js/std/builders";import{standardizeAndThrowError as U}from"@hub3js/std/operators";import{builders as y,utils as K}from"@rango-dev/wallets-core/namespaces/stellar";import*as l from"@stellar/freighter-api";var V,L,Z,Y,J,Q,m,h=s(()=>{"use strict";u();E();[V,L]=k(),Z=y.connect().action(async function(){let r=await l.requestAccess();if(r.error)throw r.error;return[K.formatAddressToCAIP(r.address)]}).before(V).or(L).or(U).build(),Y=new j("canEagerConnect").action(async function(){return!!(await l.getAddress()).address}).build(),J=v.disconnect().after(L).build(),Q=y.balanceLines.build(),m=new z("Stellar",p).action(Z).action(Y).action(J).action(Q).build()});import{signMessage as $,signTransaction as ee}from"@stellar/freighter-api";import*as n from"@stellar/stellar-sdk";import{SignerError as x,SignerErrorCode as P}from"rango-types";var re,te,g,B=s(()=>{"use strict";u();re="100",te=["invokeHostFunction","restoreFootprint","extendFootprintTtl"],g=class r{static{o(this,"Signer")}static async buildXdrTransaction(e,t){let f=await new n.Horizon.Server(b).loadAccount(t),a=new n.TransactionBuilder(f,{networkPassphrase:A,fee:e.data.baseFee??re,timebounds:e.data.preconditions.timeBounds,ledgerbounds:e.data.preconditions.ledgerBounds,minAccountSequence:e.data.preconditions.minSeqNumber??void 0,minAccountSequenceAge:e.data.preconditions.minSeqAge??void 0,minAccountSequenceLedgerGap:e.data.preconditions.minSeqLedgerGap??void 0,extraSigners:e.data.preconditions.extraSigners??void 0});if(e.data.memoXdrBase64){let i=n.xdr.Memo.fromXDR(e.data.memoXdrBase64,"base64");a.addMemo(n.Memo.fromXDRObject(i))}for(let i of e.data.operationsXdrBase64){let w=n.xdr.Operation.fromXDR(i,"base64");a.addOperation(w)}let c=a.build();return c.operations.some(i=>te.includes(i.type))?(await new n.rpc.Server(_).prepareTransaction(c)).toXDR():c.toXDR()}async signMessage(e){let t=await $(e);if(!t.signedMessage)throw new Error(t.error);return typeof t.signedMessage=="string"?t.signedMessage:t.signedMessage.toString("hex")}async signAndSendTx(e,t){let d=new n.Horizon.Server(b),f=await r.buildXdrTransaction(e,t),a=await ee(f);if(a.error)throw new x(P.SIGN_TX_ERROR,void 0,a.error);let c=new n.Transaction(a.signedTxXdr,A),S=await d.submitTransaction(c);if(!S.successful)throw new x(P.SIGN_TX_ERROR,"Error submitting transaction",void 0);return{hash:S.hash}}}});var C={};W(C,{Signer:()=>g,namespace:()=>m});var O=s(()=>{"use strict";h();B()});import{DefaultSignerFactory as ne,TransactionType as oe}from"rango-types";async function T(){let{Signer:r}=await Promise.resolve().then(()=>(O(),C)),e=new ne;return e.registerSigner(oe.STELLAR,new r),e}var X=s(()=>{"use strict";o(T,"getSigners")});import{LegacyNetworks as ae}from"@rango-dev/wallets-core/legacy";import"rango-types";var p,b,_,A,I,u=s(()=>{"use strict";X();p="frighter",b="https://horizon.stellar.org",_="https://mainnet.sorobanrpc.com",A="Public Global Stellar Network ; September 2015",I={name:"Freighter",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/freighter/icon.svg",extensions:{chrome:"https://chromewebstore.google.com/detail/freighter/bcacfldlkkdogcmkkibnjlakofdplcbk",firefox:"https://addons.mozilla.org/en-US/firefox/addon/freighter/",brave:"https://chromewebstore.google.com/detail/freighter/bcacfldlkkdogcmkkibnjlakofdplcbk",homepage:"https://www.freighter.app/"},properties:[{name:"namespaces",value:{selection:"multiple",data:[{label:"Stellar",value:"Stellar",id:"STELLAR",getSupportedChains:r=>r.filter(e=>e.name===ae.STELLAR)}]}},{name:"signers",value:{getSigners:async()=>T()}}]}});import{defineVersions as se}from"@hub3js/core/utils";u();h();import{ProviderBuilder as ie}from"@hub3js/core";import*as M from"@stellar/freighter-api";async function D(){return(await M.isConnected()).isConnected}o(D,"checkInstallation");var N=o(()=>new ie(p).init(function(r){let[,e]=r.state(),t=o(d=>e("installed",d),"setInstallState");D().then(t).catch(console.error)}).config("metadata",I).add("stellar",m).build(),"buildProvider");var Ue=o(()=>se().version("1.0.0",N()).build(),"versions");export{Ue as versions};
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/namespaces/stellar/hooks.ts", "../src/namespaces/stellar/namespace.ts", "../src/namespaces/stellar/signer.ts", "../src/namespaces/stellar/mod.ts", "../src/signer.ts", "../src/constants.ts", "../src/mod.ts", "../src/provider.ts", "../src/utils.ts"],
4
+ "sourcesContent": ["import type { StellarActions } from '@rango-dev/wallets-core/namespaces/stellar';\n\nimport { ChangeAccountSubscriberBuilder } from '@hub3js/std/hooks';\nimport { utils } from '@rango-dev/wallets-core/namespaces/stellar';\nimport { WatchWalletChanges } from '@stellar/freighter-api';\n\nconst WATCH_WALLET_INTERVAL = 1000; // how often you want to check for changes in the wallet\n\nexport function changeAccountSubscriberBuilder() {\n return new ChangeAccountSubscriberBuilder<\n { address: string },\n WatchWalletChanges,\n StellarActions\n >()\n .getInstance(() => new WatchWalletChanges(WATCH_WALLET_INTERVAL))\n .format(async (_, payload) => [utils.formatAddressToCAIP(payload.address)])\n .addEventListener((instance, callback) => {\n instance.watch(callback);\n })\n .onSwitchAccount((event, context) => {\n if (!event.payload.address) {\n context.action('disconnect');\n event.preventDefault();\n }\n })\n .removeEventListener((instance) => {\n instance.stop();\n })\n .build();\n}\n", "import type { StellarActions } from '@rango-dev/wallets-core/namespaces/stellar';\n\nimport { ActionBuilder, NamespaceBuilder } from '@hub3js/core';\nimport * as commonBuilders from '@hub3js/std/builders';\nimport { standardizeAndThrowError } from '@hub3js/std/operators';\nimport { builders, utils } from '@rango-dev/wallets-core/namespaces/stellar';\nimport * as freighterApi from '@stellar/freighter-api';\n\nimport { WALLET_ID } from '../../constants.js';\n\nimport { changeAccountSubscriberBuilder } from './hooks.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n changeAccountSubscriberBuilder();\n\nconst connect = builders\n .connect()\n .action(async function () {\n const result = await freighterApi.requestAccess();\n\n if (result.error) {\n throw result.error;\n }\n\n return [utils.formatAddressToCAIP(result.address)];\n })\n .before(changeAccountSubscriber)\n .or(changeAccountCleanup)\n .or(standardizeAndThrowError)\n .build();\n\nconst canEagerConnect = new ActionBuilder<StellarActions, 'canEagerConnect'>(\n 'canEagerConnect'\n)\n .action(async function () {\n const result = await freighterApi.getAddress();\n return !!result.address;\n })\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<StellarActions>()\n .after(changeAccountCleanup)\n .build();\n\nconst balanceLines = builders.balanceLines.build();\n\nconst namespace = new NamespaceBuilder<StellarActions>('Stellar', WALLET_ID)\n .action(connect)\n .action(canEagerConnect)\n .action(disconnect)\n .action(balanceLines)\n .build();\n\nexport { namespace };\n", "import { signMessage, signTransaction } from '@stellar/freighter-api';\nimport * as StellarSdk from '@stellar/stellar-sdk';\nimport {\n type GenericSigner,\n SignerError,\n SignerErrorCode,\n type StellarTransaction,\n} from 'rango-types';\n\nimport { HORIZON_URL, NETWORK_PASSPHRASE, RPC_URL } from '../../constants.js';\n\nexport const BASE_FEE = '100';\n\nconst SOROBAN_OP_TYPES = [\n 'invokeHostFunction',\n 'restoreFootprint',\n 'extendFootprintTtl',\n];\n\nexport class Signer implements GenericSigner<StellarTransaction> {\n static async buildXdrTransaction(\n tx: StellarTransaction,\n address: string\n ): Promise<string> {\n const server = new StellarSdk.Horizon.Server(HORIZON_URL);\n const account = await server.loadAccount(address);\n\n const builder = new StellarSdk.TransactionBuilder(account, {\n networkPassphrase: NETWORK_PASSPHRASE,\n fee: tx.data.baseFee ?? BASE_FEE,\n timebounds: tx.data.preconditions.timeBounds,\n ledgerbounds: tx.data.preconditions.ledgerBounds,\n minAccountSequence: tx.data.preconditions.minSeqNumber ?? undefined,\n minAccountSequenceAge: tx.data.preconditions.minSeqAge ?? undefined,\n minAccountSequenceLedgerGap:\n tx.data.preconditions.minSeqLedgerGap ?? undefined,\n extraSigners: tx.data.preconditions.extraSigners ?? undefined,\n });\n\n if (tx.data.memoXdrBase64) {\n const memoXDRObject = StellarSdk.xdr.Memo.fromXDR(\n tx.data.memoXdrBase64,\n 'base64'\n );\n builder.addMemo(StellarSdk.Memo.fromXDRObject(memoXDRObject));\n }\n\n for (const operationXdrBase64 of tx.data.operationsXdrBase64) {\n const operationXDRObject = StellarSdk.xdr.Operation.fromXDR(\n operationXdrBase64,\n 'base64'\n );\n builder.addOperation(operationXDRObject);\n }\n\n const transaction = builder.build();\n\n const isSorobanTransaction = transaction.operations.some((operation) =>\n SOROBAN_OP_TYPES.includes(operation.type)\n );\n\n if (isSorobanTransaction) {\n const rpcServer = new StellarSdk.rpc.Server(RPC_URL);\n const preparedTransaction = await rpcServer.prepareTransaction(\n transaction\n );\n const xdrTransaction = preparedTransaction.toXDR();\n return xdrTransaction;\n }\n\n const xdrTransaction = transaction.toXDR();\n\n return xdrTransaction;\n }\n\n async signMessage(msg: string): Promise<string> {\n const signature = await signMessage(msg);\n\n if (!signature.signedMessage) {\n throw new Error(signature.error);\n }\n\n if (typeof signature.signedMessage === 'string') {\n return signature.signedMessage;\n }\n\n return signature.signedMessage.toString('hex');\n }\n\n async signAndSendTx(\n tx: StellarTransaction,\n address: string\n ): Promise<{ hash: string }> {\n const server = new StellarSdk.Horizon.Server(HORIZON_URL);\n\n const xdrTransaction = await Signer.buildXdrTransaction(tx, address);\n\n const signature = await signTransaction(xdrTransaction);\n\n if (signature.error) {\n throw new SignerError(\n SignerErrorCode.SIGN_TX_ERROR,\n undefined,\n signature.error\n );\n }\n\n const signedTransaction = new StellarSdk.Transaction(\n signature.signedTxXdr,\n NETWORK_PASSPHRASE\n );\n\n const result = await server.submitTransaction(signedTransaction);\n\n if (!result.successful) {\n throw new SignerError(\n SignerErrorCode.SIGN_TX_ERROR,\n 'Error submitting transaction',\n undefined\n );\n }\n\n return { hash: result.hash };\n }\n}\n", "export { namespace } from './namespace.js';\nexport { Signer } from './signer.js';\n", "import type { SignerFactory } from 'rango-types';\n\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nexport default async function getSigners(): Promise<SignerFactory> {\n const { Signer: StellarSigner } = await import('./namespaces/stellar/mod.js');\n\n const signers = new DefaultSignerFactory();\n signers.registerSigner(TxType.STELLAR, new StellarSigner());\n return signers;\n}\n", "import type { ProviderMetadata } from '@hub3js/core';\n\nimport { LegacyNetworks } from '@rango-dev/wallets-core/legacy';\nimport { type BlockchainMeta } from 'rango-types';\n\nimport getSigners from './signer.js';\n\nexport const WALLET_ID = 'frighter';\nexport const HORIZON_URL = 'https://horizon.stellar.org';\nexport const RPC_URL = 'https://mainnet.sorobanrpc.com';\nexport const NETWORK_PASSPHRASE =\n 'Public Global Stellar Network ; September 2015';\n\nexport const metadata: ProviderMetadata = {\n name: 'Freighter',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/freighter/icon.svg',\n extensions: {\n chrome:\n 'https://chromewebstore.google.com/detail/freighter/bcacfldlkkdogcmkkibnjlakofdplcbk',\n firefox: 'https://addons.mozilla.org/en-US/firefox/addon/freighter/',\n brave:\n 'https://chromewebstore.google.com/detail/freighter/bcacfldlkkdogcmkkibnjlakofdplcbk',\n homepage: 'https://www.freighter.app/',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'multiple',\n data: [\n {\n label: 'Stellar',\n value: 'Stellar',\n id: 'STELLAR',\n getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n allBlockchains.filter(\n (blockchainMeta) =>\n blockchainMeta.name === LegacyNetworks.STELLAR\n ),\n },\n ],\n },\n },\n {\n name: 'signers',\n value: { getSigners: async () => getSigners() },\n },\n ],\n};\n", "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';\n\nimport { metadata, WALLET_ID } from './constants.js';\nimport { namespace as stellar } from './namespaces/stellar/namespace.js';\nimport { checkInstallation } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n const setInstallState = (result: boolean) =>\n setState('installed', result);\n\n checkInstallation().then(setInstallState).catch(console.error);\n })\n .config('metadata', metadata)\n .add('stellar', stellar)\n .build();\n\nexport { buildProvider };\n", "import * as freighterApi from '@stellar/freighter-api';\n\nexport async function checkInstallation(): Promise<boolean> {\n const result = await freighterApi.isConnected();\n\n return result.isConnected;\n}\n"],
5
+ "mappings": "gLAEA,OAAS,kCAAAA,MAAsC,oBAC/C,OAAS,SAAAC,MAAa,6CACtB,OAAS,sBAAAC,MAA0B,yBAI5B,SAASC,GAAiC,CAC/C,OAAO,IAAIH,EAIT,EACC,YAAY,IAAM,IAAIE,EAAmBE,CAAqB,CAAC,EAC/D,OAAO,MAAOC,EAAGC,IAAY,CAACL,EAAM,oBAAoBK,EAAQ,OAAO,CAAC,CAAC,EACzE,iBAAiB,CAACC,EAAUC,IAAa,CACxCD,EAAS,MAAMC,CAAQ,CACzB,CAAC,EACA,gBAAgB,CAACC,EAAOC,IAAY,CAC9BD,EAAM,QAAQ,UACjBC,EAAQ,OAAO,YAAY,EAC3BD,EAA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CACF,CACF,CACF,EACA,CACE,KAAM,UACN,MAAO,CAAE,WAAY,SAAYW,EAAW,CAAE,CAChD,CACF,CACF,IChDA,OAAS,kBAAAC,OAAsB,qBCE/BC,IACAC,IAHA,OAAS,mBAAAC,OAAuB,eCAhC,UAAYC,MAAkB,yBAE9B,eAAsBC,GAAsC,CAG1D,OAFe,MAAmB,cAAY,GAEhC,WAChB,CAJsBC,EAAAD,EAAA,qBDItB,IAAME,EAAgBC,EAAA,IACpB,IAAIC,GAAgBC,CAAS,EAC1B,KAAK,SAAUC,EAAS,CACvB,GAAM,CAAC,CAAEC,CAAQ,EAAID,EAAQ,MAAM,EAC7BE,EAAkBL,EAACM,GACvBF,EAAS,YAAaE,CAAM,EADN,mBAGxBC,EAAkB,EAAE,KAAKF,CAAe,EAAE,MAAM,QAAQ,KAAK,CAC/D,CAAC,EACA,OAAO,WAAYG,CAAQ,EAC3B,IAAI,UAAWC,CAAO,EACtB,MAAM,EAXW,iBDFtB,IAAMC,GAAWC,EAAA,IACfC,GAAe,EAAE,QAAQ,QAASC,EAAc,CAAC,EAAE,MAAM,EAD1C",
6
+ "names": ["ChangeAccountSubscriberBuilder", "utils", "WatchWalletChanges", "changeAccountSubscriberBuilder", "WATCH_WALLET_INTERVAL", "_", "payload", "instance", "callback", "event", "context", "init_hooks", "__esmMin", "__name", "ActionBuilder", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "builders", "utils", "freighterApi", "changeAccountSubscriber", "changeAccountCleanup", "connect", "canEagerConnect", "disconnect", "balanceLines", "namespace", "init_namespace", "__esmMin", "init_constants", "init_hooks", "changeAccountSubscriberBuilder", "result", "WALLET_ID", "signMessage", "signTransaction", "StellarSdk", "SignerError", "SignerErrorCode", "BASE_FEE", "SOROBAN_OP_TYPES", "Signer", "init_signer", "__esmMin", "init_constants", "_Signer", "__name", "tx", "address", "account", "HORIZON_URL", "builder", "NETWORK_PASSPHRASE", "memoXDRObject", "operationXdrBase64", "operationXDRObject", "transaction", "operation", "RPC_URL", "msg", "signature", "server", "xdrTransaction", "signedTransaction", "result", "mod_exports", "__export", "Signer", "namespace", "init_mod", "__esmMin", "init_namespace", "init_signer", "DefaultSignerFactory", "TxType", "getSigners", "StellarSigner", "signers", "init_signer", "__esmMin", "__name", "LegacyNetworks", "WALLET_ID", "HORIZON_URL", "RPC_URL", "NETWORK_PASSPHRASE", "metadata", "init_constants", "__esmMin", "init_signer", "allBlockchains", "blockchainMeta", "getSigners", "defineVersions", "init_constants", "init_namespace", "ProviderBuilder", "freighterApi", "checkInstallation", "__name", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "setInstallState", "result", "checkInstallation", "metadata", "namespace", "versions", "__name", "defineVersions", "buildProvider"]
7
+ }
@@ -0,0 +1,3 @@
1
+ import type { StellarActions } from '@rango-dev/wallets-core/namespaces/stellar';
2
+ export declare function changeAccountSubscriberBuilder(): [import("@hub3js/core").Subscriber<StellarActions>, import("@hub3js/core").SubscriberCleanUp<StellarActions>];
3
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/namespaces/stellar/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAQjF,wBAAgB,8BAA8B,kHAqB7C"}
@@ -0,0 +1,3 @@
1
+ export { namespace } from './namespace.js';
2
+ export { Signer } from './signer.js';
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/namespaces/stellar/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { StellarActions } from '@rango-dev/wallets-core/namespaces/stellar';
2
+ declare const namespace: import("@hub3js/core").ProxiedNamespace<StellarActions>;
3
+ export { namespace };
4
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../../src/namespaces/stellar/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AA+CjF,QAAA,MAAM,SAAS,yDAKL,CAAC;AAEX,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type GenericSigner, type StellarTransaction } from 'rango-types';
2
+ export declare const BASE_FEE = "100";
3
+ export declare class Signer implements GenericSigner<StellarTransaction> {
4
+ static buildXdrTransaction(tx: StellarTransaction, address: string): Promise<string>;
5
+ signMessage(msg: string): Promise<string>;
6
+ signAndSendTx(tx: StellarTransaction, address: string): Promise<{
7
+ hash: string;
8
+ }>;
9
+ }
10
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../../src/namespaces/stellar/signer.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAGlB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAIrB,eAAO,MAAM,QAAQ,QAAQ,CAAC;AAQ9B,qBAAa,MAAO,YAAW,aAAa,CAAC,kBAAkB,CAAC;WACjD,mBAAmB,CAC9B,EAAE,EAAE,kBAAkB,EACtB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC;IAoDZ,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAczC,aAAa,CACjB,EAAE,EAAE,kBAAkB,EACtB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAgC7B"}
@@ -0,0 +1 @@
1
+ {"inputs":{"src/namespaces/stellar/hooks.ts":{"bytes":1033,"imports":[{"path":"@hub3js/std/hooks","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/stellar","kind":"import-statement","external":true},{"path":"@stellar/freighter-api","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/namespaces/stellar/namespace.ts":{"bytes":1554,"imports":[{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@hub3js/std/builders","kind":"import-statement","external":true},{"path":"@hub3js/std/operators","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/stellar","kind":"import-statement","external":true},{"path":"@stellar/freighter-api","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"../../constants.js"},{"path":"src/namespaces/stellar/hooks.ts","kind":"import-statement","original":"./hooks.js"}],"format":"esm"},"src/namespaces/stellar/signer.ts":{"bytes":3533,"imports":[{"path":"@stellar/freighter-api","kind":"import-statement","external":true},{"path":"@stellar/stellar-sdk","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"../../constants.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/namespaces/stellar/mod.ts":{"bytes":82,"imports":[{"path":"src/namespaces/stellar/namespace.ts","kind":"import-statement","original":"./namespace.js"},{"path":"src/namespaces/stellar/signer.ts","kind":"import-statement","original":"./signer.js"}],"format":"esm"},"src/signer.ts":{"bytes":411,"imports":[{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/namespaces/stellar/mod.ts","kind":"dynamic-import","original":"./namespaces/stellar/mod.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/constants.ts":{"bytes":1535,"imports":[{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signer.ts","kind":"import-statement","original":"./signer.js"}],"format":"esm"},"src/utils.ts":{"bytes":202,"imports":[{"path":"@stellar/freighter-api","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/provider.ts":{"bytes":634,"imports":[{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"},{"path":"src/namespaces/stellar/namespace.ts","kind":"import-statement","original":"./namespaces/stellar/namespace.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/mod.ts":{"bytes":209,"imports":[{"path":"@hub3js/core/utils","kind":"import-statement","external":true},{"path":"src/provider.ts","kind":"import-statement","original":"./provider.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/mod.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":15777},"dist/mod.js":{"imports":[{"path":"@hub3js/std/hooks","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/stellar","kind":"import-statement","external":true},{"path":"@stellar/freighter-api","kind":"import-statement","external":true},{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@hub3js/std/builders","kind":"import-statement","external":true},{"path":"@hub3js/std/operators","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/stellar","kind":"import-statement","external":true},{"path":"@stellar/freighter-api","kind":"import-statement","external":true},{"path":"@stellar/freighter-api","kind":"import-statement","external":true},{"path":"@stellar/stellar-sdk","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@hub3js/core/utils","kind":"import-statement","external":true},{"path":"@hub3js/core","kind":"import-statement","external":true},{"path":"@stellar/freighter-api","kind":"import-statement","external":true}],"exports":["versions"],"entryPoint":"src/mod.ts","inputs":{"src/namespaces/stellar/hooks.ts":{"bytesInOutput":547},"src/namespaces/stellar/namespace.ts":{"bytesInOutput":747},"src/namespaces/stellar/signer.ts":{"bytesInOutput":1688},"src/namespaces/stellar/mod.ts":{"bytesInOutput":81},"src/signer.ts":{"bytesInOutput":248},"src/constants.ts":{"bytesInOutput":898},"src/mod.ts":{"bytesInOutput":112},"src/provider.ts":{"bytesInOutput":254},"src/utils.ts":{"bytesInOutput":127}},"bytes":4934}}}
@@ -0,0 +1,3 @@
1
+ declare const buildProvider: () => import("@hub3js/core").Provider<Record<"stellar", import("@rango-dev/wallets-core/namespaces/stellar").StellarActions>>;
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,+HAWP,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;AAIjD,wBAA8B,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC,CAMjE"}
@@ -0,0 +1,2 @@
1
+ export declare function checkInstallation(): Promise<boolean>;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAI1D"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@rango-dev/provider-freighter",
3
+ "version": "0.0.0-experimental-82bcc5d9-20260608",
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": "node ../../scripts/build/command.mjs --path wallets/provider-freighter --inputs src/mod.ts",
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.60.1",
25
+ "@hub3js/std": "^0.1.1",
26
+ "@rango-dev/wallets-shared": "^0.0.0-experimental-82bcc5d9-20260608",
27
+ "@stellar/freighter-api": "^6.0.1",
28
+ "@stellar/stellar-sdk": "^15.0.1",
29
+ "rango-types": "^0.5.0"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ }
34
+ }
package/readme.md ADDED
@@ -0,0 +1,14 @@
1
+ # Freighter Provider
2
+
3
+ Freighter integration for hub.
4
+ [Homepage](https://www.freighter.app/) | [Docs](https://docs.freighter.app/docs/)
5
+
6
+ More about implementation status can be found [here](../readme.md).
7
+
8
+ ## Implementation notes/limitations
9
+
10
+ ### Group
11
+
12
+ Freighter supports **Stellar**.
13
+
14
+ More wallet information can be found in [readme.md](../readme.md).
@@ -0,0 +1,49 @@
1
+ import type { ProviderMetadata } from '@hub3js/core';
2
+
3
+ import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
4
+ import { type BlockchainMeta } from 'rango-types';
5
+
6
+ import getSigners from './signer.js';
7
+
8
+ export const WALLET_ID = 'frighter';
9
+ export const HORIZON_URL = 'https://horizon.stellar.org';
10
+ export const RPC_URL = 'https://mainnet.sorobanrpc.com';
11
+ export const NETWORK_PASSPHRASE =
12
+ 'Public Global Stellar Network ; September 2015';
13
+
14
+ export const metadata: ProviderMetadata = {
15
+ name: 'Freighter',
16
+ icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/freighter/icon.svg',
17
+ extensions: {
18
+ chrome:
19
+ 'https://chromewebstore.google.com/detail/freighter/bcacfldlkkdogcmkkibnjlakofdplcbk',
20
+ firefox: 'https://addons.mozilla.org/en-US/firefox/addon/freighter/',
21
+ brave:
22
+ 'https://chromewebstore.google.com/detail/freighter/bcacfldlkkdogcmkkibnjlakofdplcbk',
23
+ homepage: 'https://www.freighter.app/',
24
+ },
25
+ properties: [
26
+ {
27
+ name: 'namespaces',
28
+ value: {
29
+ selection: 'multiple',
30
+ data: [
31
+ {
32
+ label: 'Stellar',
33
+ value: 'Stellar',
34
+ id: 'STELLAR',
35
+ getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
36
+ allBlockchains.filter(
37
+ (blockchainMeta) =>
38
+ blockchainMeta.name === LegacyNetworks.STELLAR
39
+ ),
40
+ },
41
+ ],
42
+ },
43
+ },
44
+ {
45
+ name: 'signers',
46
+ value: { getSigners: async () => getSigners() },
47
+ },
48
+ ],
49
+ };
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,30 @@
1
+ import type { StellarActions } from '@rango-dev/wallets-core/namespaces/stellar';
2
+
3
+ import { ChangeAccountSubscriberBuilder } from '@hub3js/std/hooks';
4
+ import { utils } from '@rango-dev/wallets-core/namespaces/stellar';
5
+ import { WatchWalletChanges } from '@stellar/freighter-api';
6
+
7
+ const WATCH_WALLET_INTERVAL = 1000; // how often you want to check for changes in the wallet
8
+
9
+ export function changeAccountSubscriberBuilder() {
10
+ return new ChangeAccountSubscriberBuilder<
11
+ { address: string },
12
+ WatchWalletChanges,
13
+ StellarActions
14
+ >()
15
+ .getInstance(() => new WatchWalletChanges(WATCH_WALLET_INTERVAL))
16
+ .format(async (_, payload) => [utils.formatAddressToCAIP(payload.address)])
17
+ .addEventListener((instance, callback) => {
18
+ instance.watch(callback);
19
+ })
20
+ .onSwitchAccount((event, context) => {
21
+ if (!event.payload.address) {
22
+ context.action('disconnect');
23
+ event.preventDefault();
24
+ }
25
+ })
26
+ .removeEventListener((instance) => {
27
+ instance.stop();
28
+ })
29
+ .build();
30
+ }
@@ -0,0 +1,2 @@
1
+ export { namespace } from './namespace.js';
2
+ export { Signer } from './signer.js';
@@ -0,0 +1,55 @@
1
+ import type { StellarActions } from '@rango-dev/wallets-core/namespaces/stellar';
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 { builders, utils } from '@rango-dev/wallets-core/namespaces/stellar';
7
+ import * as freighterApi from '@stellar/freighter-api';
8
+
9
+ import { WALLET_ID } from '../../constants.js';
10
+
11
+ import { changeAccountSubscriberBuilder } from './hooks.js';
12
+
13
+ const [changeAccountSubscriber, changeAccountCleanup] =
14
+ changeAccountSubscriberBuilder();
15
+
16
+ const connect = builders
17
+ .connect()
18
+ .action(async function () {
19
+ const result = await freighterApi.requestAccess();
20
+
21
+ if (result.error) {
22
+ throw result.error;
23
+ }
24
+
25
+ return [utils.formatAddressToCAIP(result.address)];
26
+ })
27
+ .before(changeAccountSubscriber)
28
+ .or(changeAccountCleanup)
29
+ .or(standardizeAndThrowError)
30
+ .build();
31
+
32
+ const canEagerConnect = new ActionBuilder<StellarActions, 'canEagerConnect'>(
33
+ 'canEagerConnect'
34
+ )
35
+ .action(async function () {
36
+ const result = await freighterApi.getAddress();
37
+ return !!result.address;
38
+ })
39
+ .build();
40
+
41
+ const disconnect = commonBuilders
42
+ .disconnect<StellarActions>()
43
+ .after(changeAccountCleanup)
44
+ .build();
45
+
46
+ const balanceLines = builders.balanceLines.build();
47
+
48
+ const namespace = new NamespaceBuilder<StellarActions>('Stellar', WALLET_ID)
49
+ .action(connect)
50
+ .action(canEagerConnect)
51
+ .action(disconnect)
52
+ .action(balanceLines)
53
+ .build();
54
+
55
+ export { namespace };
@@ -0,0 +1,125 @@
1
+ import { signMessage, signTransaction } from '@stellar/freighter-api';
2
+ import * as StellarSdk from '@stellar/stellar-sdk';
3
+ import {
4
+ type GenericSigner,
5
+ SignerError,
6
+ SignerErrorCode,
7
+ type StellarTransaction,
8
+ } from 'rango-types';
9
+
10
+ import { HORIZON_URL, NETWORK_PASSPHRASE, RPC_URL } from '../../constants.js';
11
+
12
+ export const BASE_FEE = '100';
13
+
14
+ const SOROBAN_OP_TYPES = [
15
+ 'invokeHostFunction',
16
+ 'restoreFootprint',
17
+ 'extendFootprintTtl',
18
+ ];
19
+
20
+ export class Signer implements GenericSigner<StellarTransaction> {
21
+ static async buildXdrTransaction(
22
+ tx: StellarTransaction,
23
+ address: string
24
+ ): Promise<string> {
25
+ const server = new StellarSdk.Horizon.Server(HORIZON_URL);
26
+ const account = await server.loadAccount(address);
27
+
28
+ const builder = new StellarSdk.TransactionBuilder(account, {
29
+ networkPassphrase: NETWORK_PASSPHRASE,
30
+ fee: tx.data.baseFee ?? BASE_FEE,
31
+ timebounds: tx.data.preconditions.timeBounds,
32
+ ledgerbounds: tx.data.preconditions.ledgerBounds,
33
+ minAccountSequence: tx.data.preconditions.minSeqNumber ?? undefined,
34
+ minAccountSequenceAge: tx.data.preconditions.minSeqAge ?? undefined,
35
+ minAccountSequenceLedgerGap:
36
+ tx.data.preconditions.minSeqLedgerGap ?? undefined,
37
+ extraSigners: tx.data.preconditions.extraSigners ?? undefined,
38
+ });
39
+
40
+ if (tx.data.memoXdrBase64) {
41
+ const memoXDRObject = StellarSdk.xdr.Memo.fromXDR(
42
+ tx.data.memoXdrBase64,
43
+ 'base64'
44
+ );
45
+ builder.addMemo(StellarSdk.Memo.fromXDRObject(memoXDRObject));
46
+ }
47
+
48
+ for (const operationXdrBase64 of tx.data.operationsXdrBase64) {
49
+ const operationXDRObject = StellarSdk.xdr.Operation.fromXDR(
50
+ operationXdrBase64,
51
+ 'base64'
52
+ );
53
+ builder.addOperation(operationXDRObject);
54
+ }
55
+
56
+ const transaction = builder.build();
57
+
58
+ const isSorobanTransaction = transaction.operations.some((operation) =>
59
+ SOROBAN_OP_TYPES.includes(operation.type)
60
+ );
61
+
62
+ if (isSorobanTransaction) {
63
+ const rpcServer = new StellarSdk.rpc.Server(RPC_URL);
64
+ const preparedTransaction = await rpcServer.prepareTransaction(
65
+ transaction
66
+ );
67
+ const xdrTransaction = preparedTransaction.toXDR();
68
+ return xdrTransaction;
69
+ }
70
+
71
+ const xdrTransaction = transaction.toXDR();
72
+
73
+ return xdrTransaction;
74
+ }
75
+
76
+ async signMessage(msg: string): Promise<string> {
77
+ const signature = await signMessage(msg);
78
+
79
+ if (!signature.signedMessage) {
80
+ throw new Error(signature.error);
81
+ }
82
+
83
+ if (typeof signature.signedMessage === 'string') {
84
+ return signature.signedMessage;
85
+ }
86
+
87
+ return signature.signedMessage.toString('hex');
88
+ }
89
+
90
+ async signAndSendTx(
91
+ tx: StellarTransaction,
92
+ address: string
93
+ ): Promise<{ hash: string }> {
94
+ const server = new StellarSdk.Horizon.Server(HORIZON_URL);
95
+
96
+ const xdrTransaction = await Signer.buildXdrTransaction(tx, address);
97
+
98
+ const signature = await signTransaction(xdrTransaction);
99
+
100
+ if (signature.error) {
101
+ throw new SignerError(
102
+ SignerErrorCode.SIGN_TX_ERROR,
103
+ undefined,
104
+ signature.error
105
+ );
106
+ }
107
+
108
+ const signedTransaction = new StellarSdk.Transaction(
109
+ signature.signedTxXdr,
110
+ NETWORK_PASSPHRASE
111
+ );
112
+
113
+ const result = await server.submitTransaction(signedTransaction);
114
+
115
+ if (!result.successful) {
116
+ throw new SignerError(
117
+ SignerErrorCode.SIGN_TX_ERROR,
118
+ 'Error submitting transaction',
119
+ undefined
120
+ );
121
+ }
122
+
123
+ return { hash: result.hash };
124
+ }
125
+ }
@@ -0,0 +1,20 @@
1
+ import { ProviderBuilder } from '@hub3js/core';
2
+
3
+ import { metadata, WALLET_ID } from './constants.js';
4
+ import { namespace as stellar } from './namespaces/stellar/namespace.js';
5
+ import { checkInstallation } from './utils.js';
6
+
7
+ const buildProvider = () =>
8
+ new ProviderBuilder(WALLET_ID)
9
+ .init(function (context) {
10
+ const [, setState] = context.state();
11
+ const setInstallState = (result: boolean) =>
12
+ setState('installed', result);
13
+
14
+ checkInstallation().then(setInstallState).catch(console.error);
15
+ })
16
+ .config('metadata', metadata)
17
+ .add('stellar', stellar)
18
+ .build();
19
+
20
+ export { buildProvider };
package/src/signer.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { SignerFactory } from 'rango-types';
2
+
3
+ import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';
4
+
5
+ export default async function getSigners(): Promise<SignerFactory> {
6
+ const { Signer: StellarSigner } = await import('./namespaces/stellar/mod.js');
7
+
8
+ const signers = new DefaultSignerFactory();
9
+ signers.registerSigner(TxType.STELLAR, new StellarSigner());
10
+ return signers;
11
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,7 @@
1
+ import * as freighterApi from '@stellar/freighter-api';
2
+
3
+ export async function checkInstallation(): Promise<boolean> {
4
+ const result = await freighterApi.isConnected();
5
+
6
+ return result.isConnected;
7
+ }