Skip to content

Commit 5bcdf0b

Browse files
committed
Update Freighter module and react example
1 parent cb0a9e6 commit 5bcdf0b

File tree

3 files changed

+89
-38
lines changed

3 files changed

+89
-38
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ See [standard-version](https://github.com/conventional-changelog/standard-versio
3838
- Fully remove both `submit` and `submitUrl` parameters
3939
- And many more.
4040

41+
### Fix
42+
43+
- Update Freighter module `signAuthEntry` method so it ignores the freighter-api types and follow a similar logic to the
44+
`signMessage` method uses (handle both a string and buffer response)
45+
4146
### [1.9.5](https://github.com/Creit-Tech/Stellar-Wallets-Kit/compare/v1.9.4...v1.9.5) (2025-09-05)
4247

4348
### Add

examples/vite-react/src/App.tsx

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
1-
import { Component } from 'react'
2-
import './App.css'
1+
import { Component } from "react";
2+
import "./App.css";
33

4-
import { KitEventType, SwkAppDarkTheme } from "@creit-tech/stellar-wallets-kit/types";
4+
import {
5+
KitEventType,
6+
SwkAppDarkTheme,
7+
} from "@creit-tech/stellar-wallets-kit/types";
58
import { StellarWalletsKit } from "@creit-tech/stellar-wallets-kit/sdk";
6-
import { activeAddress, activeModule, } from "@creit-tech/stellar-wallets-kit/state";
7-
import { ButtonMode } from '@creit-tech/stellar-wallets-kit/components';
8-
import { defaultModules } from '@creit-tech/stellar-wallets-kit/modules/utils';
9+
import {
10+
activeAddress,
11+
activeModule,
12+
} from "@creit-tech/stellar-wallets-kit/state";
13+
import { ButtonMode } from "@creit-tech/stellar-wallets-kit/components";
14+
import { defaultModules } from "@creit-tech/stellar-wallets-kit/modules/utils";
915
import { TrezorModule } from "@creit-tech/stellar-wallets-kit/modules/trezor";
16+
import { LedgerModule } from "@creit-tech/stellar-wallets-kit/modules/ledger";
1017
import { WalletConnectModule } from "@creit-tech/stellar-wallets-kit/modules/wallet-connect";
1118

12-
import { Account, Networks, Operation, TransactionBuilder, } from "@stellar/stellar-sdk";
19+
import {
20+
Account,
21+
Networks,
22+
Operation,
23+
TransactionBuilder,
24+
} from "@stellar/stellar-sdk";
1325

1426
StellarWalletsKit.init({
1527
theme: {
1628
...SwkAppDarkTheme,
17-
primary: '#1a1a1a',
18-
'primary-foreground': 'rgba(255, 255, 255, 0.87)',
19-
'border-radius': '8px',
20-
shadow: 'none',
21-
background: '#1a1a1a',
22-
foreground: 'rgba(255, 255, 255, 0.87)'
29+
primary: "#1a1a1a",
30+
"primary-foreground": "rgba(255, 255, 255, 0.87)",
31+
"border-radius": "8px",
32+
shadow: "none",
33+
background: "#1a1a1a",
34+
foreground: "rgba(255, 255, 255, 0.87)",
2335
},
2436
modules: [
2537
...defaultModules(),
38+
new LedgerModule(),
2639
new TrezorModule({
2740
appName: "Stellar Wallets Kit",
2841
appUrl: "http://localhost:5173",
@@ -34,8 +47,8 @@ StellarWalletsKit.init({
3447
name: "Stellar Wallets Kit",
3548
description: "Add support to all Stellar Wallets with a single library",
3649
icons: [],
37-
url: 'http://localhost:5173/',
38-
}
50+
url: "http://localhost:5173/",
51+
},
3952
}),
4053
],
4154
});
@@ -51,25 +64,25 @@ export class App extends Component<any, any> {
5164
* IMPORTANT: In this example we are not destroying these subscriptions,
5265
* in your app you should do it when components are unmount.
5366
*/
54-
StellarWalletsKit.on(KitEventType.STATE_UPDATED, event => {
67+
StellarWalletsKit.on(KitEventType.STATE_UPDATED, (event) => {
5568
console.log(`Address updated:`, event.payload.address);
56-
this.setState({address: event.payload.address});
69+
this.setState({ address: event.payload.address });
5770
});
58-
StellarWalletsKit.on(KitEventType.WALLET_SELECTED, event => {
71+
StellarWalletsKit.on(KitEventType.WALLET_SELECTED, (event) => {
5972
console.log(`Wallet ID:`, event.payload.id);
60-
this.setState({moduleId: event.payload.id});
73+
this.setState({ moduleId: event.payload.id });
6174
});
6275
StellarWalletsKit.on(KitEventType.DISCONNECT, () => {
63-
this.setState({address: undefined, productName: undefined});
76+
this.setState({ address: undefined, productName: undefined });
6477
});
65-
StellarWalletsKit.createButton(document.querySelector('#button')!, {
78+
StellarWalletsKit.createButton(document.querySelector("#button")!, {
6679
mode: ButtonMode.free,
6780
});
6881
}
6982

7083
async authModal(): Promise<void> {
7184
try {
72-
const {address} = await StellarWalletsKit.authModal();
85+
const { address } = await StellarWalletsKit.authModal();
7386
console.log(`Address fetched:`, address);
7487
} catch (e) {
7588
console.error(e);
@@ -81,7 +94,7 @@ export class App extends Component<any, any> {
8194
}
8295

8396
async signTransaction(): Promise<void> {
84-
const {address} = await StellarWalletsKit.getAddress();
97+
const { address } = await StellarWalletsKit.getAddress();
8598
console.log("StellarWalletsKit::getAddress", address);
8699
const tx = new TransactionBuilder(new Account(address, "-1"), {
87100
networkPassphrase: Networks.PUBLIC,
@@ -96,12 +109,28 @@ export class App extends Component<any, any> {
96109
)
97110
.build();
98111

99-
const {signedTxXdr} = await StellarWalletsKit.signTransaction(tx.toXDR(), {
112+
const { signedTxXdr } = await StellarWalletsKit.signTransaction(
113+
tx.toXDR(),
114+
{
115+
networkPassphrase: Networks.PUBLIC,
116+
address,
117+
},
118+
);
119+
120+
console.log("Signed Transaction:", signedTxXdr);
121+
}
122+
123+
async signAuthEntry(): Promise<void> {
124+
const { address } = await StellarWalletsKit.getAddress();
125+
const xdr =
126+
"AAAACXrDOZdUTjF10ma9AiQ5sizbFlCMARY/JuXLKj4QRal5Ueb3t2qeufIDkl6TAAAAAAAAAAHD5Dhm6FraoWtNw3xmsftfw43aav9gLsi5kDYD1ccr/gAAAApzdGFydF9nYW1lAAAAAAAFAAAAAy2DQRwAAAASAAAAAAAAAACO+drsns+C8ivJ7BbEvGPuuaf+RI7JYRYQh3tTDoG6yAAAABIAAAAAAAAAADzwlU9pvQCCZwaS876OkOohieXRjEidV8RoVpxgVhODAAAACgAAAAAAAAAAAAAAAAAPQkAAAAAKAAAAAAAAAAAAAAAAAA9CQAAAAAEAAAAAAAAAAQ711IO2j2xojpimQQ1dzE4A9Kskd2MeHXPKwLGFTKYYAAAACnN0YXJ0X2dhbWUAAAAAAAYAAAASAAAAAcPkOGboWtqha03DfGax+1/Djdpq/2AuyLmQNgPVxyv+AAAAAy2DQRwAAAASAAAAAAAAAACO+drsns+C8ivJ7BbEvGPuuaf+RI7JYRYQh3tTDoG6yAAAABIAAAAAAAAAADzwlU9pvQCCZwaS876OkOohieXRjEidV8RoVpxgVhODAAAACgAAAAAAAAAAAAAAAAAPQkAAAAAKAAAAAAAAAAAAAAAAAA9CQAAAAAA=";
127+
128+
const { signedAuthEntry } = await StellarWalletsKit.signAuthEntry(xdr, {
100129
networkPassphrase: Networks.PUBLIC,
101130
address,
102131
});
103132

104-
console.log("Signed Transaction:", signedTxXdr);
133+
console.log("Signed Auth Entry:", signedAuthEntry);
105134
}
106135

107136
render() {
@@ -111,37 +140,46 @@ export class App extends Component<any, any> {
111140
<div className="card">
112141
<section>
113142
<div>
114-
<button onClick={ () => this.authModal() }>
143+
<button onClick={() => this.authModal()}>
115144
Connect Wallet
116145
</button>
117146

118-
<button onClick={ () => this.disconnect() }>
147+
<button onClick={() => this.disconnect()}>
119148
Disconnect
120149
</button>
121150

122-
<button onClick={ () => this.signTransaction() }>
151+
<button onClick={() => this.signTransaction()}>
123152
Sign transaction
124153
</button>
125154

126-
<button onClick={ () => StellarWalletsKit.profileModal() }>
155+
<button onClick={() => this.signAuthEntry()}>
156+
Sign auth Entry
157+
</button>
158+
159+
<button onClick={() => StellarWalletsKit.profileModal()}>
127160
Profile Modal
128161
</button>
129162
</div>
130163

131164
<div>
132165
<p>
133-
Your selected wallet is: <br/> { this.state.moduleId }
166+
Your selected wallet is: <br /> {this.state.moduleId}
134167
</p>
135168
<p>
136-
Your account is: <br/> { this.state.address &&
137-
`${ this.state.address.slice(0, 4) }....${ this.state.address.slice(-6) }` }
169+
Your account is: <br /> {this.state.address &&
170+
`${this.state.address.slice(0, 4)}....${
171+
this.state.address.slice(-6)
172+
}`}
138173
</p>
139174

140-
<div style={ {marginBottom: '3rem'} }></div>
175+
<div style={{ marginBottom: "3rem" }}></div>
141176

142177
<div>
143-
<p>This is the built button, it follows the theme configured in the kit but we are using the "free" mode
144-
of the button so it uses our global React defined styles :</p>
178+
<p>
179+
This is the built button, it follows the theme configured in
180+
the kit but we are using the "free" mode of the button so it
181+
uses our global React defined styles :
182+
</p>
145183
<div id="button"></div>
146184
</div>
147185
</div>
@@ -152,4 +190,4 @@ export class App extends Component<any, any> {
152190
}
153191
}
154192

155-
export default App
193+
export default App;

src/sdk/modules/freighter.module.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,13 @@ export class FreighterModule implements ModuleInterface {
111111
try {
112112
await this.runChecks();
113113

114+
/**
115+
* TODO: We are using "any" because the Freighter api has a bug with the types, they will fix it in a future version. Remove the "any" once we update the dependency
116+
*/
114117
const { signedAuthEntry, signerAddress, error } = await signAuthEntry(authEntry, {
115118
address: opts?.address,
116119
networkPassphrase: opts?.networkPassphrase,
117-
});
120+
}) as any;
118121

119122
if (error) return Promise.reject(error);
120123
if (!signedAuthEntry) {
@@ -124,7 +127,12 @@ export class FreighterModule implements ModuleInterface {
124127
});
125128
}
126129

127-
return { signedAuthEntry: encodeBase64(new Uint8Array(signedAuthEntry)), signerAddress: signerAddress };
130+
return {
131+
signedAuthEntry: typeof signedAuthEntry === "string"
132+
? signedAuthEntry
133+
: encodeBase64(new Uint8Array(signedAuthEntry)),
134+
signerAddress: signerAddress,
135+
};
128136
} catch (e) {
129137
throw parseError(e);
130138
}

0 commit comments

Comments
 (0)