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

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,25 +38,20 @@ 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(`Para connector: signDirect chainId 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(`Para connector: signerAddress ${signerAddress} not found in wallet`);
39
46
  }
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
+ const signer = new ParaProtoSigner(this.para, this.prefix, (yield this.wallet()).id);
48
+ const result = yield signer.signDirect(signerAddress, signDoc);
47
49
  return {
48
50
  signed: {
49
51
  bodyBytes: result.signed.bodyBytes,
50
52
  authInfoBytes: result.signed.authInfoBytes,
51
53
  chainId: result.signed.chainId,
52
- accountNumber: Long.fromString(result.signed.accountNumber.toString())
54
+ accountNumber: result.signed.accountNumber
53
55
  },
54
56
  signature: result.signature
55
57
  };
@@ -57,248 +59,216 @@ class ParaOfflineSigner {
57
59
  }
58
60
  }
59
61
  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
- }
62
+ constructor(config, chains = null) {
67
63
  this.config = config;
68
- this.paraWebClient = new ParaWeb(config.env, config.apiKey);
69
- this.isModalClosed = true;
64
+ this.chains = chains;
65
+ this.enabledChainIds = /* @__PURE__ */ new Set();
66
+ if (!(config == null ? void 0 : config.paraWeb)) {
67
+ throw new Error("Para connector: missing paraWeb instance in config");
68
+ }
69
+ this.events = config.events;
70
+ this.paraWebClient = config.paraWeb;
71
+ this.noModal = config.noModal;
70
72
  }
71
- waitForLogin() {
72
- return __async(this, arguments, function* (timeoutMs = TEN_MINUTES_MS) {
73
- const startTime = Date.now();
74
- while (Date.now() - startTime < timeoutMs) {
75
- if (yield this.paraWebClient.isFullyLoggedIn()) {
76
- return true;
77
- }
78
- if (this.isModalClosed) {
79
- throw new Error("user closed modal");
80
- }
81
- yield new Promise((resolve) => setTimeout(resolve, 2e3));
73
+ ensureChainEnabled(chainId) {
74
+ return __async(this, null, function* () {
75
+ if (!this.enabledChainIds.has(chainId)) {
76
+ throw new Error(`Para connector: chain ${chainId} was not enabled via wallet.enable()`);
77
+ }
78
+ if (!(yield this.paraWebClient.isFullyLoggedIn())) {
79
+ throw new Error("Para connector: wallet is not connected \u2013 call enable() first");
82
80
  }
83
- throw new Error("timed out waiting for user to log in");
84
81
  });
85
82
  }
86
- waitForAccounts(chainIds, timeoutMs = 5e3) {
83
+ waitForLogin(timeoutMs = 6e4) {
87
84
  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;
93
- }
94
- yield new Promise((resolve) => setTimeout(resolve, 500));
85
+ const deadline = Date.now() + timeoutMs;
86
+ let delay = 500;
87
+ const MAX_DELAY = 5e3;
88
+ while (true) {
89
+ if (yield this.paraWebClient.isFullyLoggedIn()) return;
90
+ if (Date.now() >= deadline) throw new Error("Para connector: login timeout");
91
+ yield new Promise((r) => setTimeout(r, delay));
92
+ delay = Math.min(delay * 1.5, MAX_DELAY);
95
93
  }
96
- throw new Error("timed out waiting for accounts to load");
97
94
  });
98
95
  }
99
- enable(chainIds) {
96
+ waitForAccounts(timeoutMs = 5e3) {
100
97
  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) {
104
- return;
105
- }
98
+ const deadline = Date.now() + timeoutMs;
99
+ let delay = 250;
100
+ const MAX_DELAY = 1e3;
101
+ while (true) {
102
+ const wallets = this.paraWebClient.getWalletsByType("COSMOS");
103
+ if (wallets.length) return wallets;
104
+ if (Date.now() >= deadline) throw new Error("Para connector: no COSMOS wallets found after login");
105
+ yield new Promise((r) => setTimeout(r, delay));
106
+ delay = Math.min(delay * 1.5, MAX_DELAY);
106
107
  }
107
- this.isModalClosed = false;
108
- renderModal(this.paraWebClient, this.config.modalProps, () => {
109
- this.isModalClosed = true;
110
- });
111
- yield this.waitForLogin();
108
+ });
109
+ }
110
+ hasCosmosWallet() {
111
+ return __async(this, null, function* () {
112
+ return (yield this.paraWebClient.isFullyLoggedIn()) && this.paraWebClient.getWalletsByType("COSMOS").length > 0;
113
+ });
114
+ }
115
+ enable(chainIdsInput) {
116
+ return __async(this, null, function* () {
117
+ var _a, _b, _c, _d;
118
+ const chainIds = toArray(chainIdsInput);
119
+ const previousEnabled = new Set(this.enabledChainIds);
112
120
  try {
113
- yield this.waitForAccounts(chainIds);
114
- } catch (error) {
115
- throw new Error("accounts not available after login");
121
+ chainIds.forEach((id) => this.enabledChainIds.add(id));
122
+ if (yield this.hasCosmosWallet()) {
123
+ (_b = (_a = this.events) == null ? void 0 : _a.onEnabled) == null ? void 0 : _b.call(_a, chainIds, this);
124
+ return;
125
+ }
126
+ if (!this.noModal) {
127
+ throw new Error("Modal rendering not supported in core library. Use @getpara/graz-integration for modal support.");
128
+ }
129
+ yield this.waitForLogin();
130
+ yield this.waitForAccounts();
131
+ (_d = (_c = this.events) == null ? void 0 : _c.onEnabled) == null ? void 0 : _d.call(_c, chainIds, this);
132
+ } catch (err) {
133
+ this.enabledChainIds = previousEnabled;
134
+ throw err;
116
135
  }
117
136
  });
118
137
  }
138
+ disconnect() {
139
+ return __async(this, null, function* () {
140
+ yield this.paraWebClient.logout();
141
+ this.enabledChainIds.clear();
142
+ });
143
+ }
144
+ getFirstWallet() {
145
+ return __async(this, null, function* () {
146
+ const [wallet] = yield this.waitForAccounts();
147
+ return wallet;
148
+ });
149
+ }
150
+ getBech32Prefix(chainId) {
151
+ var _a, _b, _c;
152
+ return ((_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";
153
+ }
119
154
  getParaWebClient() {
120
155
  return this.paraWebClient;
121
156
  }
122
157
  getConfig() {
123
158
  return this.config;
124
159
  }
160
+ buildHybridSigner(chainId) {
161
+ const aminoSigner = this.getOfflineSignerOnlyAmino(chainId);
162
+ const directSigner = new ParaOfflineSigner(chainId, this);
163
+ return {
164
+ getAccounts: () => directSigner.getAccounts(),
165
+ signAmino: (signer, signDoc) => aminoSigner.signAmino(signer, signDoc),
166
+ signDirect: (signer, signDoc) => directSigner.signDirect(signer, signDoc)
167
+ };
168
+ }
125
169
  getKey(chainId) {
126
170
  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}`);
136
- }
137
- const account = accountData[0];
171
+ yield this.ensureChainEnabled(chainId);
172
+ const wallet = yield this.getFirstWallet();
173
+ const signer = new ParaProtoSigner(this.paraWebClient, this.getBech32Prefix(chainId), wallet.id);
174
+ const [account] = yield signer.getAccounts();
175
+ if (!account) throw new Error(`Para connector: wallet ${wallet.id} has no Cosmos accounts`);
138
176
  return {
139
- address: fromBech32(account.address).data,
140
- bech32Address: account.address,
177
+ name: "Para Wallet",
141
178
  algo: account.algo,
142
- name: account.address,
143
179
  pubKey: account.pubkey,
180
+ address: fromBech32(account.address).data,
181
+ bech32Address: account.address,
144
182
  isKeystone: false,
145
183
  isNanoLedger: false
146
184
  };
147
185
  });
148
186
  }
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
187
  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}`);
188
+ void this.ensureChainEnabled(chainId);
189
+ const wallet = this.paraWebClient.getWalletsByType("COSMOS")[0];
190
+ if (!wallet) {
191
+ throw new Error(`Para connector: no wallets found when requesting Amino signer for ${chainId}`);
163
192
  }
164
- const bech32Prefix = this.getBech32Prefix(chainId);
165
- return new ParaAminoSigner(this.paraWebClient, bech32Prefix, wallets[0].id);
193
+ return new ParaAminoSigner(this.paraWebClient, this.getBech32Prefix(chainId), wallet.id);
194
+ }
195
+ getOfflineSigner(chainId) {
196
+ void this.ensureChainEnabled(chainId);
197
+ return this.buildHybridSigner(chainId);
166
198
  }
167
199
  getOfflineSignerAuto(chainId) {
168
- return Promise.resolve(this.getOfflineSignerOnlyAmino(chainId));
200
+ return __async(this, null, function* () {
201
+ void this.ensureChainEnabled(chainId);
202
+ return this.buildHybridSigner(chainId);
203
+ });
169
204
  }
170
- signAmino(chainId, signer, signDoc) {
205
+ signAmino(chainId, signer, signDoc, _signOptions) {
171
206
  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}`);
207
+ yield this.ensureChainEnabled(chainId);
208
+ try {
209
+ const wallet = yield this.getFirstWallet();
210
+ const signerImpl = new ParaAminoSigner(this.paraWebClient, this.getBech32Prefix(chainId), wallet.id);
211
+ return yield signerImpl.signAmino(signer, signDoc);
212
+ } catch (err) {
213
+ throw new Error(`Para connector: signAmino failed \u2013 ${err.message}`);
176
214
  }
177
- const bech32Prefix = this.getBech32Prefix(chainId);
178
- const walletSigner = new ParaAminoSigner(this.paraWebClient, bech32Prefix, wallets[0].id);
179
- return walletSigner.signAmino(signer, signDoc);
180
215
  });
181
216
  }
182
- signDirect(chainId, signer, signDoc) {
217
+ signDirect(chainId, signer, signDoc, _signOptions) {
183
218
  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}`);
219
+ var _a, _b;
220
+ yield this.ensureChainEnabled(chainId);
221
+ try {
222
+ const wallet = yield this.getFirstWallet();
223
+ const signerImpl = new ParaProtoSigner(this.paraWebClient, this.getBech32Prefix(chainId), wallet.id);
224
+ const convertedSignDoc = {
225
+ bodyBytes: (_a = signDoc.bodyBytes) != null ? _a : new Uint8Array(),
226
+ authInfoBytes: (_b = signDoc.authInfoBytes) != null ? _b : new Uint8Array(),
227
+ chainId: signDoc.chainId,
228
+ accountNumber: typeof signDoc.accountNumber === "bigint" ? signDoc.accountNumber : BigInt(signDoc.accountNumber)
229
+ };
230
+ const result = yield signerImpl.signDirect(signer, convertedSignDoc);
231
+ return {
232
+ signed: {
233
+ bodyBytes: result.signed.bodyBytes,
234
+ authInfoBytes: result.signed.authInfoBytes,
235
+ chainId: result.signed.chainId,
236
+ accountNumber: result.signed.accountNumber
237
+ },
238
+ signature: result.signature
239
+ };
240
+ } catch (err) {
241
+ throw new Error(`Para connector: signDirect failed \u2013 ${err.message}`);
188
242
  }
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
243
  });
210
244
  }
211
245
  signArbitrary(chainId, signer, data) {
212
246
  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
- }
247
+ yield this.ensureChainEnabled(chainId);
248
+ const encodedData = typeof data === "string" ? Buffer.from(data, "utf-8").toString("base64") : Buffer.from(data).toString("base64");
222
249
  const signDoc = {
223
250
  chain_id: "",
224
251
  account_number: "0",
225
252
  sequence: "0",
226
- fee: {
227
- gas: "0",
228
- amount: []
229
- },
253
+ fee: { gas: "0", amount: [] },
230
254
  msgs: [
231
255
  {
232
256
  type: "sign/MsgSignData",
233
- value: {
234
- signer,
235
- data: encodedData
236
- }
257
+ value: { signer, data: encodedData }
237
258
  }
238
259
  ],
239
260
  memo: ""
240
261
  };
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");
262
+ try {
263
+ const response = yield this.signAmino(chainId, signer, signDoc);
264
+ return response.signature;
265
+ } catch (err) {
266
+ throw new Error(`Para connector: signArbitrary failed \u2013 ${err.message}`);
255
267
  }
256
268
  });
257
269
  }
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
270
  }
301
271
  export {
302
272
  ParaGrazConnector,
303
- ParaOfflineSigner
273
+ toArray
304
274
  };
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
  };
package/package.json CHANGED
@@ -1,25 +1,43 @@
1
1
  {
2
2
  "name": "@getpara/graz-connector",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "2.0.0-dev.10",
4
+ "sideEffects": false,
4
5
  "type": "module",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
7
- "sideEffects": false,
8
- "dependencies": {
9
- "@getpara/react-sdk": "1.11.0",
10
- "@getpara/cosmjs-v0-integration": "1.11.0"
11
- },
12
8
  "scripts": {
13
9
  "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs",
10
+ "test": "vitest run --coverage",
14
11
  "typegen": "tsc --emitDeclarationOnly"
15
12
  },
13
+ "dependencies": {
14
+ "@getpara/cosmjs-v0-integration": "2.0.0-alpha.42",
15
+ "@getpara/web-sdk": "2.0.0-alpha.42"
16
+ },
16
17
  "devDependencies": {
17
- "@cosmjs/amino": "^0.32.3",
18
- "@cosmjs/encoding": "^0.32.3",
19
- "@cosmjs/proto-signing": "^0.32.3",
20
- "cosmjs-types": "0.9.0",
21
- "typescript": "5.1.6",
22
- "graz": "0.2.1",
23
- "@keplr-wallet/types": "0.12.221"
18
+ "@cosmjs/amino": "^0.32.4",
19
+ "@cosmjs/cosmwasm-stargate": "^0.32.4",
20
+ "@cosmjs/encoding": "^0.32.4",
21
+ "@cosmjs/launchpad": "0.27.1",
22
+ "@cosmjs/proto-signing": "^0.32.4",
23
+ "@cosmjs/stargate": "^0.32.4",
24
+ "@cosmjs/tendermint-rpc": "^0.32.4",
25
+ "@keplr-wallet/types": "0.12.156",
26
+ "cosmjs-types": "^0.9.0",
27
+ "graz": "^0.3.3",
28
+ "long": "5.3.2",
29
+ "typescript": "5.1.6"
30
+ },
31
+ "peerDependencies": {
32
+ "@cosmjs/amino": "*",
33
+ "@cosmjs/cosmwasm-stargate": "*",
34
+ "@cosmjs/encoding": "*",
35
+ "@cosmjs/launchpad": ">=0.27.1",
36
+ "@cosmjs/proto-signing": "*",
37
+ "@cosmjs/stargate": "*",
38
+ "@cosmjs/tendermint-rpc": "*",
39
+ "@keplr-wallet/types": ">=0.12.156",
40
+ "cosmjs-types": ">=0.8.0",
41
+ "graz": ">=0.3.3"
24
42
  }
25
43
  }