Skip to content

Commit e03d17d

Browse files
author
Enrique A.
committed
Update bitget module
1 parent b2e74b0 commit e03d17d

7 files changed

Lines changed: 110 additions & 81 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ out the [documentation](https://stellarwalletskit.dev/) for more details.
6464
- Hot Wallet
6565
- Klever Wallet
6666
- OneKey Wallet
67+
- Bitget Wallet
6768

6869
## Installation and usage
6970

docs/files/wallets/supported-wallets.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ These are the current supported wallets/modules:
1616
| HOT | HotWalletModule | /hotwallet | No |
1717
| Klever | KleverModule | /klever | Yes |
1818
| OneKey | OneKeyModule | /onekey | Yes |
19+
| Bitget | BitgetModule | /bitget | Yes |
1920

2021
## How to import a wallet's module?
2122

src/build_npm.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ await build({
2828
name: "./modules/albedo",
2929
path: "./sdk/modules/albedo.module.ts",
3030
},
31+
{
32+
name: "./modules/bitget",
33+
path: "./sdk/modules/bitget.module.ts",
34+
},
3135
{
3236
name: "./modules/freighter",
3337
path: "./sdk/modules/freighter.module.ts",

src/deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"./types": "./types/mod.ts",
4040
"./sdk": "./sdk/mod.ts",
4141
"./modules/albedo": "./sdk/modules/albedo.module.ts",
42+
"./modules/bitget": "./sdk/modules/bitget.module.ts",
4243
"./modules/freighter": "./sdk/modules/freighter.module.ts",
4344
"./modules/hana": "./sdk/modules/hana.module.ts",
4445
"./modules/hotwallet": "./sdk/modules/hotwallet.module.ts",

src/sdk/modules/bitget-wallet.module.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/sdk/modules/bitget.module.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { type ModuleInterface, ModuleType } from "../../types/mod.ts";
2+
import { parseError } from "../utils.ts";
3+
4+
declare const window: {
5+
bitkeep?: any;
6+
};
7+
8+
export const BITGET_WALLET_ID = "BitgetWallet";
9+
10+
export class BitgetModule implements ModuleInterface {
11+
moduleType: ModuleType = ModuleType.HOT_WALLET;
12+
productId: string = BITGET_WALLET_ID;
13+
productName: string = "Bitget Wallet";
14+
productUrl: string = "https://web3.bitget.com";
15+
productIcon: string = "https://stellar.creit.tech/wallet-icons/bitget.png";
16+
provider: any;
17+
18+
constructor() {
19+
this.provider = window.bitkeep?.stellar;
20+
}
21+
22+
async runChecks(): Promise<void> {
23+
if (!(await this.isAvailable())) {
24+
throw new Error(`${this.productName} is not connected`);
25+
}
26+
}
27+
28+
async isAvailable() {
29+
return !!this.provider;
30+
}
31+
async getAddress() {
32+
try {
33+
await this.runChecks();
34+
const address = await this.provider.connect();
35+
return { address };
36+
} catch (e) {
37+
throw parseError(e);
38+
}
39+
}
40+
async signMessage(
41+
message: string,
42+
opts?: {
43+
networkPassphrase?: string;
44+
address?: string;
45+
path?: string;
46+
},
47+
) {
48+
try {
49+
await this.runChecks();
50+
const signatureHex = await this.provider.signMessage(message, opts?.address);
51+
return { signedMessage: signatureHex };
52+
} catch (e) {
53+
throw parseError(e);
54+
}
55+
}
56+
57+
async signTransaction(
58+
xdr: string,
59+
opts?: {
60+
networkPassphrase?: string;
61+
address?: string;
62+
path?: string;
63+
submit?: boolean;
64+
submitUrl?: string;
65+
},
66+
) {
67+
try {
68+
await this.runChecks();
69+
const signedTxXdr = await this.provider.signTransaction(xdr, opts);
70+
return { signedTxXdr };
71+
} catch (e) {
72+
throw parseError(e);
73+
}
74+
}
75+
76+
async signAuthEntry(
77+
authEntry: string,
78+
opts?: {
79+
networkPassphrase?: string;
80+
address?: string;
81+
path?: string;
82+
},
83+
): Promise<{
84+
signedAuthEntry: string;
85+
signerAddress?: string;
86+
}> {
87+
throw {
88+
code: -3,
89+
message: `${this.productName} does not support the "signAuthEntry" function`,
90+
};
91+
}
92+
93+
async getNetwork() {
94+
try {
95+
await this.runChecks();
96+
return this.provider.network();
97+
} catch (e) {
98+
throw parseError(e);
99+
}
100+
}
101+
}

src/sdk/modules/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { xBullModule } from "./xbull.module.ts";
77
import { HanaModule } from "./hana.module.ts";
88
import { KleverModule } from "./klever.module.ts";
99
import { OneKeyModule } from "./onekey.module.ts";
10+
import { BitgetModule } from "./bitget.module.ts";
1011

1112
/**
1213
* This method returns all modules that don't require extra configuration before they can be loaded
@@ -27,6 +28,7 @@ export function defaultModules(opts?: {
2728
new HanaModule(),
2829
new KleverModule(),
2930
new OneKeyModule(),
31+
new BitgetModule(),
3032
];
3133
return opts?.filterBy ? modules.filter(opts.filterBy) : modules;
3234
}

0 commit comments

Comments
 (0)