@getpara/graz-connector 0.1.0-alpha.6 → 2.0.0-dev.11

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.
@@ -1,44 +1,49 @@
1
- import ParaWeb from '@getpara/react-sdk';
2
- import type { Environment, ParaModalProps } from '@getpara/react-sdk';
3
- import type { Wallet, Key as GrazKey } from 'graz';
4
- import type { OfflineAminoSigner, OfflineDirectSigner, AminoSignResponse, StdSignDoc, StdSignature, DirectSignResponse, AccountData, SignDoc as KeplrSignDoc } from '@keplr-wallet/types';
5
- import Long from 'long';
1
+ import { Wallet, SignDoc as GrazSignDoc } from 'graz';
2
+ import { ParaWeb, Wallet as ParaWallet } from '@getpara/web-sdk';
3
+ import { DirectSignResponse, OfflineDirectSigner } from '@cosmjs/proto-signing';
4
+ import { AminoSignResponse, OfflineAminoSigner, StdSignature, StdSignDoc } from '@cosmjs/amino';
5
+ import { ChainInfo, KeplrSignOptions } from '@keplr-wallet/types';
6
+ export type ParaGrazConnectorEvents = {
7
+ onEnabled?: (chainIds: string[], connector: ParaGrazConnector) => void;
8
+ };
6
9
  export interface ParaGrazConfig {
7
- apiKey: string;
8
- env: Environment;
9
- modalProps?: ParaModalProps;
10
- }
11
- export declare class ParaOfflineSigner implements OfflineDirectSigner {
12
- private chainId;
13
- private paraWebClient;
14
- constructor(chainId: string, paraWebClient: ParaWeb);
15
- getAccounts(): Promise<readonly AccountData[]>;
16
- signDirect(signerAddress: string, signDoc: KeplrSignDoc): Promise<DirectSignResponse>;
10
+ paraWeb: ParaWeb;
11
+ events?: ParaGrazConnectorEvents;
12
+ noModal?: boolean;
17
13
  }
14
+ export declare function toArray<T>(v: T | T[]): T[];
18
15
  export declare class ParaGrazConnector implements Omit<Wallet, 'experimentalSuggestChain'> {
19
- private paraWebClient;
20
- private config;
21
- private isModalClosed;
22
- constructor(config: ParaGrazConfig);
23
- closeModal: () => void;
24
- private waitForLogin;
25
- private waitForAccounts;
26
- enable(chainIds: string | string[]): Promise<void>;
16
+ protected readonly config: ParaGrazConfig;
17
+ protected readonly chains: ChainInfo[] | null;
18
+ protected paraWebClient: ParaWeb;
19
+ protected enabledChainIds: Set<string>;
20
+ protected readonly events?: ParaGrazConnectorEvents;
21
+ protected noModal?: boolean;
22
+ constructor(config: ParaGrazConfig, chains?: ChainInfo[] | null);
23
+ protected ensureChainEnabled(chainId: string): Promise<void>;
24
+ protected waitForLogin(timeoutMs?: number): Promise<void>;
25
+ protected waitForAccounts(timeoutMs?: number): Promise<ParaWallet[]>;
26
+ protected hasCosmosWallet(): Promise<boolean>;
27
+ enable(chainIdsInput: string | string[]): Promise<void>;
28
+ disconnect(): Promise<void>;
29
+ getFirstWallet(): Promise<ParaWallet>;
30
+ getBech32Prefix(chainId: string): string;
27
31
  getParaWebClient(): ParaWeb;
28
32
  getConfig(): ParaGrazConfig;
29
- getKey(chainId: string): Promise<GrazKey>;
30
- getOfflineSigner(chainId: string): OfflineAminoSigner & OfflineDirectSigner;
33
+ protected buildHybridSigner(chainId: string): OfflineAminoSigner & OfflineDirectSigner;
34
+ getKey(chainId: string): Promise<{
35
+ name: string;
36
+ algo: import("@cosmjs/amino").Algo;
37
+ pubKey: Uint8Array;
38
+ address: Uint8Array;
39
+ bech32Address: string;
40
+ isKeystone: boolean;
41
+ isNanoLedger: boolean;
42
+ }>;
31
43
  getOfflineSignerOnlyAmino(chainId: string): OfflineAminoSigner;
44
+ getOfflineSigner(chainId: string): OfflineAminoSigner & OfflineDirectSigner;
32
45
  getOfflineSignerAuto(chainId: string): Promise<OfflineAminoSigner | OfflineDirectSigner>;
33
- signAmino(chainId: string, signer: string, signDoc: StdSignDoc): Promise<AminoSignResponse>;
34
- signDirect(chainId: string, signer: string, signDoc: {
35
- bodyBytes?: Uint8Array;
36
- authInfoBytes?: Uint8Array;
37
- chainId?: string;
38
- accountNumber?: Long;
39
- }): Promise<DirectSignResponse>;
46
+ signAmino(chainId: string, signer: string, signDoc: StdSignDoc, _signOptions?: KeplrSignOptions): Promise<AminoSignResponse>;
47
+ signDirect(chainId: string, signer: string, signDoc: GrazSignDoc, _signOptions?: KeplrSignOptions): Promise<DirectSignResponse>;
40
48
  signArbitrary(chainId: string, signer: string, data: string | Uint8Array): Promise<StdSignature>;
41
- disconnect(): Promise<void>;
42
- private ensureConnected;
43
- private getBech32Prefix;
44
49
  }
package/dist/connector.js CHANGED
@@ -1,29 +1,36 @@
1
1
  "use client";
2
2
  import {
3
- __async,
4
- __spreadProps,
5
- __spreadValues
6
- } from "./chunk-IV3L3JVM.js";
7
- import ParaWeb from "@getpara/react-sdk";
8
- import { getChainInfo } from "graz";
9
- import { ParaAminoSigner, ParaProtoSigner } from "@getpara/cosmjs-v0-integration";
3
+ __async
4
+ } from "./chunk-M66XENHI.js";
10
5
  import { fromBech32 } from "@cosmjs/encoding";
11
- import { renderModal } from "./connectorModal.js";
12
- import Long from "long";
13
- const TEN_MINUTES_MS = 6e5;
6
+ import { ParaAminoSigner, ParaProtoSigner } from "@getpara/cosmjs-v0-integration";
7
+ function toArray(v) {
8
+ return Array.isArray(v) ? v : [v];
9
+ }
14
10
  class ParaOfflineSigner {
15
- constructor(chainId, paraWebClient) {
11
+ constructor(chainId, connector) {
16
12
  this.chainId = chainId;
17
- this.paraWebClient = paraWebClient;
13
+ this.connector = connector;
14
+ }
15
+ get para() {
16
+ return this.connector.getParaWebClient();
17
+ }
18
+ get prefix() {
19
+ return this.connector.getBech32Prefix(this.chainId);
20
+ }
21
+ wallet() {
22
+ return __async(this, null, function* () {
23
+ return this.connector.getFirstWallet();
24
+ });
18
25
  }
19
26
  getAccounts() {
20
27
  return __async(this, null, function* () {
21
- const key = yield getKey(this.paraWebClient, this.chainId);
28
+ const key = yield this.connector.getKey(this.chainId);
22
29
  return [
23
30
  {
24
- address: key.address,
31
+ address: key.bech32Address,
25
32
  algo: key.algo,
26
- pubkey: key.pubkey
33
+ pubkey: key.pubKey
27
34
  }
28
35
  ];
29
36
  });
@@ -31,274 +38,274 @@ class ParaOfflineSigner {
31
38
  signDirect(signerAddress, signDoc) {
32
39
  return __async(this, null, function* () {
33
40
  if (this.chainId !== signDoc.chainId) {
34
- throw new Error("Chain ID does not match signer chain ID");
41
+ throw new Error(`Chain ID mismatch: expected ${this.chainId}, got ${signDoc.chainId}`);
35
42
  }
36
43
  const accounts = yield this.getAccounts();
37
- if (accounts.find((account) => account.address !== signerAddress)) {
38
- throw new Error("Signer address does not match wallet address");
44
+ if (accounts.every((a) => a.address !== signerAddress)) {
45
+ throw new Error(`Signer address ${signerAddress} not found in wallet`);
46
+ }
47
+ const signer = new ParaProtoSigner(this.para, this.prefix, (yield this.wallet()).id);
48
+ try {
49
+ const result = yield signer.signDirect(signerAddress, signDoc);
50
+ return {
51
+ signed: {
52
+ bodyBytes: result.signed.bodyBytes,
53
+ authInfoBytes: result.signed.authInfoBytes,
54
+ chainId: result.signed.chainId,
55
+ accountNumber: result.signed.accountNumber
56
+ },
57
+ signature: result.signature
58
+ };
59
+ } catch (err) {
60
+ throw new Error(`Direct signing failed: ${err instanceof Error ? err.message : "Unknown error"}`);
39
61
  }
40
- const convertedSignDoc = {
41
- bodyBytes: signDoc.bodyBytes,
42
- authInfoBytes: signDoc.authInfoBytes,
43
- chainId: signDoc.chainId,
44
- accountNumber: typeof signDoc.accountNumber === "string" ? signDoc.accountNumber : signDoc.accountNumber.toString()
45
- };
46
- const result = yield requestSignature(this.paraWebClient, this.chainId, signerAddress, convertedSignDoc);
47
- return {
48
- signed: {
49
- bodyBytes: result.signed.bodyBytes,
50
- authInfoBytes: result.signed.authInfoBytes,
51
- chainId: result.signed.chainId,
52
- accountNumber: Long.fromString(result.signed.accountNumber.toString())
53
- },
54
- signature: result.signature
55
- };
56
62
  });
57
63
  }
58
64
  }
59
65
  class ParaGrazConnector {
60
- constructor(config) {
61
- this.closeModal = () => {
62
- this.isModalClosed = true;
63
- };
64
- if (!config || !config.apiKey || !config.env) {
65
- throw new Error("Para Connector: Missing API Key or Environment in config.");
66
- }
66
+ constructor(config, chains = null) {
67
67
  this.config = config;
68
- this.paraWebClient = new ParaWeb(config.env, config.apiKey);
69
- this.isModalClosed = true;
68
+ this.chains = chains;
69
+ this.enabledChainIds = /* @__PURE__ */ new Set();
70
+ if (!(config == null ? void 0 : config.paraWeb)) {
71
+ throw new Error("ParaWeb instance required in config");
72
+ }
73
+ this.events = config.events;
74
+ this.paraWebClient = config.paraWeb;
75
+ this.noModal = config.noModal;
76
+ }
77
+ ensureChainEnabled(chainId) {
78
+ return __async(this, null, function* () {
79
+ if (!this.enabledChainIds.has(chainId)) {
80
+ throw new Error(`Chain ${chainId} not enabled. Call enable() first`);
81
+ }
82
+ if (!(yield this.paraWebClient.isFullyLoggedIn())) {
83
+ throw new Error("Para wallet not authenticated");
84
+ }
85
+ });
70
86
  }
71
- waitForLogin() {
72
- return __async(this, arguments, function* (timeoutMs = TEN_MINUTES_MS) {
73
- const startTime = Date.now();
74
- while (Date.now() - startTime < timeoutMs) {
87
+ waitForLogin(timeoutMs = 6e4) {
88
+ return __async(this, null, function* () {
89
+ const deadline = Date.now() + timeoutMs;
90
+ let delay = 500;
91
+ const MAX_DELAY = 5e3;
92
+ while (true) {
75
93
  if (yield this.paraWebClient.isFullyLoggedIn()) {
76
- return true;
94
+ return;
77
95
  }
78
- if (this.isModalClosed) {
79
- throw new Error("user closed modal");
96
+ if (Date.now() >= deadline) {
97
+ throw new Error(`Login timeout after ${timeoutMs / 1e3}s`);
80
98
  }
81
- yield new Promise((resolve) => setTimeout(resolve, 2e3));
99
+ yield new Promise((r) => setTimeout(r, delay));
100
+ delay = Math.min(delay * 1.5, MAX_DELAY);
82
101
  }
83
- throw new Error("timed out waiting for user to log in");
84
102
  });
85
103
  }
86
- waitForAccounts(chainIds, timeoutMs = 5e3) {
104
+ waitForAccounts(timeoutMs = 5e3) {
87
105
  return __async(this, null, function* () {
88
- const startTime = Date.now();
89
- while (Date.now() - startTime < timeoutMs) {
90
- const wallets = Object.values(this.paraWebClient.getWalletsByType("COSMOS"));
91
- if (wallets && wallets.length > 0) {
92
- return true;
106
+ const deadline = Date.now() + timeoutMs;
107
+ let delay = 250;
108
+ const MAX_DELAY = 1e3;
109
+ while (true) {
110
+ const wallets = this.paraWebClient.getWalletsByType("COSMOS");
111
+ if (wallets.length) {
112
+ return wallets;
113
+ }
114
+ if (Date.now() >= deadline) {
115
+ throw new Error("No Cosmos wallets found");
93
116
  }
94
- yield new Promise((resolve) => setTimeout(resolve, 500));
117
+ yield new Promise((r) => setTimeout(r, delay));
118
+ delay = Math.min(delay * 1.5, MAX_DELAY);
95
119
  }
96
- throw new Error("timed out waiting for accounts to load");
97
120
  });
98
121
  }
99
- enable(chainIds) {
122
+ hasCosmosWallet() {
123
+ return __async(this, null, function* () {
124
+ const isLoggedIn = yield this.paraWebClient.isFullyLoggedIn();
125
+ const wallets = this.paraWebClient.getWalletsByType("COSMOS");
126
+ return isLoggedIn && wallets.length > 0;
127
+ });
128
+ }
129
+ enable(chainIdsInput) {
100
130
  return __async(this, null, function* () {
101
- if (yield this.paraWebClient.isFullyLoggedIn()) {
102
- const wallets = Object.values(this.paraWebClient.getWalletsByType("COSMOS"));
103
- if (wallets && wallets.length > 0) {
131
+ var _a, _b, _c, _d;
132
+ const chainIds = toArray(chainIdsInput);
133
+ const previousEnabled = new Set(this.enabledChainIds);
134
+ try {
135
+ chainIds.forEach((id) => this.enabledChainIds.add(id));
136
+ if (yield this.hasCosmosWallet()) {
137
+ (_b = (_a = this.events) == null ? void 0 : _a.onEnabled) == null ? void 0 : _b.call(_a, chainIds, this);
104
138
  return;
105
139
  }
140
+ if (!this.noModal) {
141
+ throw new Error("Modal not supported. Use @getpara/graz-integration or set noModal: true");
142
+ }
143
+ yield this.waitForLogin();
144
+ yield this.waitForAccounts();
145
+ (_d = (_c = this.events) == null ? void 0 : _c.onEnabled) == null ? void 0 : _d.call(_c, chainIds, this);
146
+ } catch (err) {
147
+ this.enabledChainIds = previousEnabled;
148
+ if (err instanceof Error) {
149
+ throw err;
150
+ }
151
+ throw new Error("Failed to enable Para wallet");
152
+ }
153
+ });
154
+ }
155
+ disconnect() {
156
+ return __async(this, null, function* () {
157
+ try {
158
+ yield this.paraWebClient.logout();
159
+ } catch (err) {
160
+ throw new Error("Disconnect failed");
161
+ } finally {
162
+ this.enabledChainIds.clear();
106
163
  }
107
- this.isModalClosed = false;
108
- renderModal(this.paraWebClient, this.config.modalProps, () => {
109
- this.isModalClosed = true;
110
- });
111
- yield this.waitForLogin();
164
+ });
165
+ }
166
+ getFirstWallet() {
167
+ return __async(this, null, function* () {
112
168
  try {
113
- yield this.waitForAccounts(chainIds);
114
- } catch (error) {
115
- throw new Error("accounts not available after login");
169
+ const [wallet] = yield this.waitForAccounts();
170
+ return wallet;
171
+ } catch (err) {
172
+ throw new Error("No Para wallet available");
116
173
  }
117
174
  });
118
175
  }
176
+ getBech32Prefix(chainId) {
177
+ var _a, _b, _c;
178
+ const prefix = ((_c = (_b = (_a = this.chains) == null ? void 0 : _a.find((c) => c.chainId === chainId)) == null ? void 0 : _b.bech32Config) == null ? void 0 : _c.bech32PrefixAccAddr) || "cosmos";
179
+ return prefix;
180
+ }
119
181
  getParaWebClient() {
120
182
  return this.paraWebClient;
121
183
  }
122
184
  getConfig() {
123
185
  return this.config;
124
186
  }
187
+ buildHybridSigner(chainId) {
188
+ const aminoSigner = this.getOfflineSignerOnlyAmino(chainId);
189
+ const directSigner = new ParaOfflineSigner(chainId, this);
190
+ return {
191
+ getAccounts: () => directSigner.getAccounts(),
192
+ signAmino: (signer, signDoc) => aminoSigner.signAmino(signer, signDoc),
193
+ signDirect: (signer, signDoc) => directSigner.signDirect(signer, signDoc)
194
+ };
195
+ }
125
196
  getKey(chainId) {
126
197
  return __async(this, null, function* () {
127
- const wallets = Object.values(this.paraWebClient.getWalletsByType("COSMOS"));
128
- if (wallets.length === 0) {
129
- throw new Error(`Para Connector: No wallets found for chainId ${chainId}`);
130
- }
131
- const bech32Prefix = this.getBech32Prefix(chainId);
132
- const walletSigner = new ParaProtoSigner(this.paraWebClient, bech32Prefix, wallets[0].id);
133
- const accountData = yield walletSigner.getAccounts();
134
- if (accountData.length === 0) {
135
- throw new Error(`Para Connector: No accounts found for wallet ${wallets[0].id}`);
198
+ try {
199
+ yield this.ensureChainEnabled(chainId);
200
+ const wallet = yield this.getFirstWallet();
201
+ const signer = new ParaProtoSigner(this.paraWebClient, this.getBech32Prefix(chainId), wallet.id);
202
+ const [account] = yield signer.getAccounts();
203
+ if (!account) {
204
+ throw new Error(`No Cosmos accounts for chain ${chainId}`);
205
+ }
206
+ return {
207
+ name: "Para Wallet",
208
+ algo: account.algo,
209
+ pubKey: account.pubkey,
210
+ address: fromBech32(account.address).data,
211
+ bech32Address: account.address,
212
+ isKeystone: false,
213
+ isNanoLedger: false
214
+ };
215
+ } catch (err) {
216
+ if (err instanceof Error) {
217
+ throw err;
218
+ }
219
+ throw new Error(`Failed to get key for chain ${chainId}`);
136
220
  }
137
- const account = accountData[0];
138
- return {
139
- address: fromBech32(account.address).data,
140
- bech32Address: account.address,
141
- algo: account.algo,
142
- name: account.address,
143
- pubKey: account.pubkey,
144
- isKeystone: false,
145
- isNanoLedger: false
146
- };
147
221
  });
148
222
  }
149
- getOfflineSigner(chainId) {
150
- const aminoSigner = this.getOfflineSignerOnlyAmino(chainId);
151
- const directSigner = new ParaOfflineSigner(chainId, this.paraWebClient);
152
- const combinedSigner = {
153
- getAccounts: () => directSigner.getAccounts(),
154
- signAmino: (signerAddress, signDoc) => aminoSigner.signAmino(signerAddress, signDoc),
155
- signDirect: (signerAddress, signDoc) => directSigner.signDirect(signerAddress, signDoc)
156
- };
157
- return combinedSigner;
158
- }
159
223
  getOfflineSignerOnlyAmino(chainId) {
160
- const wallets = Object.values(this.paraWebClient.getWalletsByType("COSMOS"));
161
- if (wallets.length === 0) {
162
- throw new Error(`Para Connector: No wallets found for chainId ${chainId}`);
224
+ void this.ensureChainEnabled(chainId);
225
+ const wallet = this.paraWebClient.getWalletsByType("COSMOS")[0];
226
+ if (!wallet) {
227
+ throw new Error("No Cosmos wallet for Amino signing");
163
228
  }
164
- const bech32Prefix = this.getBech32Prefix(chainId);
165
- return new ParaAminoSigner(this.paraWebClient, bech32Prefix, wallets[0].id);
229
+ return new ParaAminoSigner(this.paraWebClient, this.getBech32Prefix(chainId), wallet.id);
230
+ }
231
+ getOfflineSigner(chainId) {
232
+ void this.ensureChainEnabled(chainId);
233
+ return this.buildHybridSigner(chainId);
166
234
  }
167
235
  getOfflineSignerAuto(chainId) {
168
- return Promise.resolve(this.getOfflineSignerOnlyAmino(chainId));
236
+ return __async(this, null, function* () {
237
+ void this.ensureChainEnabled(chainId);
238
+ return this.buildHybridSigner(chainId);
239
+ });
169
240
  }
170
- signAmino(chainId, signer, signDoc) {
241
+ signAmino(chainId, signer, signDoc, _signOptions) {
171
242
  return __async(this, null, function* () {
172
- yield this.ensureConnected();
173
- const wallets = Object.values(this.paraWebClient.getWalletsByType("COSMOS"));
174
- if (wallets.length === 0) {
175
- throw new Error(`Para Connector: No wallets found for chainId ${chainId}`);
243
+ yield this.ensureChainEnabled(chainId);
244
+ try {
245
+ const wallet = yield this.getFirstWallet();
246
+ const signerImpl = new ParaAminoSigner(this.paraWebClient, this.getBech32Prefix(chainId), wallet.id);
247
+ const response = yield signerImpl.signAmino(signer, signDoc);
248
+ return response;
249
+ } catch (err) {
250
+ throw new Error(`Amino signing failed: ${err instanceof Error ? err.message : "Unknown error"}`);
176
251
  }
177
- const bech32Prefix = this.getBech32Prefix(chainId);
178
- const walletSigner = new ParaAminoSigner(this.paraWebClient, bech32Prefix, wallets[0].id);
179
- return walletSigner.signAmino(signer, signDoc);
180
252
  });
181
253
  }
182
- signDirect(chainId, signer, signDoc) {
254
+ signDirect(chainId, signer, signDoc, _signOptions) {
183
255
  return __async(this, null, function* () {
184
- yield this.ensureConnected();
185
- const wallets = Object.values(this.paraWebClient.getWalletsByType("COSMOS"));
186
- if (wallets.length === 0) {
187
- throw new Error(`Para Connector: No wallets found for chainId ${chainId}`);
256
+ var _a, _b;
257
+ yield this.ensureChainEnabled(chainId);
258
+ try {
259
+ const wallet = yield this.getFirstWallet();
260
+ const signerImpl = new ParaProtoSigner(this.paraWebClient, this.getBech32Prefix(chainId), wallet.id);
261
+ const convertedSignDoc = {
262
+ bodyBytes: (_a = signDoc.bodyBytes) != null ? _a : new Uint8Array(),
263
+ authInfoBytes: (_b = signDoc.authInfoBytes) != null ? _b : new Uint8Array(),
264
+ chainId: signDoc.chainId,
265
+ accountNumber: typeof signDoc.accountNumber === "bigint" ? signDoc.accountNumber : BigInt(signDoc.accountNumber)
266
+ };
267
+ const result = yield signerImpl.signDirect(signer, convertedSignDoc);
268
+ return {
269
+ signed: {
270
+ bodyBytes: result.signed.bodyBytes,
271
+ authInfoBytes: result.signed.authInfoBytes,
272
+ chainId: result.signed.chainId,
273
+ accountNumber: result.signed.accountNumber
274
+ },
275
+ signature: result.signature
276
+ };
277
+ } catch (err) {
278
+ throw new Error(`Direct signing failed: ${err instanceof Error ? err.message : "Unknown error"}`);
188
279
  }
189
- const convertedSignDoc = {
190
- bodyBytes: signDoc.bodyBytes || new Uint8Array(),
191
- authInfoBytes: signDoc.authInfoBytes || new Uint8Array(),
192
- chainId: signDoc.chainId || chainId,
193
- accountNumber: signDoc.accountNumber ? signDoc.accountNumber.toString() : "0"
194
- };
195
- const bech32Prefix = this.getBech32Prefix(chainId);
196
- const walletSigner = new ParaProtoSigner(this.paraWebClient, bech32Prefix, wallets[0].id);
197
- const result = yield walletSigner.signDirect(signer, __spreadProps(__spreadValues({}, convertedSignDoc), {
198
- accountNumber: BigInt(convertedSignDoc.accountNumber)
199
- }));
200
- return {
201
- signed: {
202
- bodyBytes: result.signed.bodyBytes,
203
- authInfoBytes: result.signed.authInfoBytes,
204
- chainId: result.signed.chainId,
205
- accountNumber: Long.fromString(result.signed.accountNumber.toString())
206
- },
207
- signature: result.signature
208
- };
209
280
  });
210
281
  }
211
282
  signArbitrary(chainId, signer, data) {
212
283
  return __async(this, null, function* () {
213
- yield this.ensureConnected();
214
- let encodedData;
215
- let isADR36WithString = false;
216
- if (typeof data === "string") {
217
- encodedData = Buffer.from(data).toString("base64");
218
- isADR36WithString = true;
219
- } else {
220
- encodedData = Buffer.from(data).toString("base64");
221
- }
284
+ yield this.ensureChainEnabled(chainId);
285
+ const encodedData = typeof data === "string" ? Buffer.from(data, "utf-8").toString("base64") : Buffer.from(data).toString("base64");
222
286
  const signDoc = {
223
287
  chain_id: "",
224
288
  account_number: "0",
225
289
  sequence: "0",
226
- fee: {
227
- gas: "0",
228
- amount: []
229
- },
290
+ fee: { gas: "0", amount: [] },
230
291
  msgs: [
231
292
  {
232
293
  type: "sign/MsgSignData",
233
- value: {
234
- signer,
235
- data: encodedData
236
- }
294
+ value: { signer, data: encodedData }
237
295
  }
238
296
  ],
239
297
  memo: ""
240
298
  };
241
- const response = yield this.signAmino(chainId, signer, signDoc);
242
- return response.signature;
243
- });
244
- }
245
- disconnect() {
246
- return __async(this, null, function* () {
247
- yield this.paraWebClient.logout();
248
- });
249
- }
250
- ensureConnected() {
251
- return __async(this, null, function* () {
252
- const isConnected = yield this.paraWebClient.isFullyLoggedIn();
253
- if (!isConnected) {
254
- throw new Error("Wallet is not connected, please connect first");
299
+ try {
300
+ const response = yield this.signAmino(chainId, signer, signDoc);
301
+ return response.signature;
302
+ } catch (err) {
303
+ throw new Error(`Arbitrary signing failed: ${err instanceof Error ? err.message : "Unknown error"}`);
255
304
  }
256
305
  });
257
306
  }
258
- getBech32Prefix(chainId) {
259
- var _a;
260
- const chainInfo = getChainInfo({ chainId });
261
- if ((_a = chainInfo == null ? void 0 : chainInfo.bech32Config) == null ? void 0 : _a.bech32PrefixAccAddr) {
262
- return chainInfo.bech32Config.bech32PrefixAccAddr;
263
- }
264
- return "cosmos";
265
- }
266
- }
267
- function getKey(paraWebClient, chainId) {
268
- return __async(this, null, function* () {
269
- var _a;
270
- const wallets = Object.values(paraWebClient.getWalletsByType("COSMOS"));
271
- if (wallets.length < 1) {
272
- throw Error("No wallets available");
273
- }
274
- const chainInfo = getChainInfo({ chainId });
275
- const bech32Prefix = ((_a = chainInfo == null ? void 0 : chainInfo.bech32Config) == null ? void 0 : _a.bech32PrefixAccAddr) || "cosmos";
276
- const walletSigner = new ParaProtoSigner(paraWebClient, bech32Prefix, wallets[0].id);
277
- const accountData = (yield walletSigner.getAccounts())[0];
278
- if (!accountData) {
279
- throw new Error("No account data found");
280
- }
281
- return accountData;
282
- });
283
- }
284
- function requestSignature(paraWebClient, chainId, signerAddress, signDoc) {
285
- return __async(this, null, function* () {
286
- var _a;
287
- const isConnected = yield paraWebClient.isFullyLoggedIn();
288
- if (!isConnected) {
289
- throw new Error("Wallet is not connected, please connect first");
290
- }
291
- const wallets = Object.values(paraWebClient.getWalletsByType("COSMOS"));
292
- if (wallets.length === 0) {
293
- throw new Error("No wallets available");
294
- }
295
- const chainInfo = getChainInfo({ chainId });
296
- const bech32Prefix = ((_a = chainInfo == null ? void 0 : chainInfo.bech32Config) == null ? void 0 : _a.bech32PrefixAccAddr) || "cosmos";
297
- const walletSigner = new ParaProtoSigner(paraWebClient, bech32Prefix, wallets[0].id);
298
- return walletSigner.signDirect(signerAddress, signDoc);
299
- });
300
307
  }
301
308
  export {
302
309
  ParaGrazConnector,
303
- ParaOfflineSigner
310
+ toArray
304
311
  };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export { WalletType, AuthLayout, AuthMethod, OAuthMethod, Environment } from '@getpara/react-sdk';
2
- export { ParaGrazConnector } from './connector.js';
1
+ export { toArray, ParaGrazConnector } from './connector.js';
3
2
  export type { ParaGrazConfig } from './connector.js';
package/dist/index.js CHANGED
@@ -1,12 +1,7 @@
1
1
  "use client";
2
- import "./chunk-IV3L3JVM.js";
3
- import { WalletType, AuthLayout, AuthMethod, OAuthMethod, Environment } from "@getpara/react-sdk";
4
- import { ParaGrazConnector } from "./connector.js";
2
+ import "./chunk-M66XENHI.js";
3
+ import { toArray, ParaGrazConnector } from "./connector.js";
5
4
  export {
6
- AuthLayout,
7
- AuthMethod,
8
- Environment,
9
- OAuthMethod,
10
5
  ParaGrazConnector,
11
- WalletType
6
+ toArray
12
7
  };