@onekeyfe/onekey-cosmos-provider 2.2.7-alpha.2 → 2.2.7-alpha.4
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/dist/BBNCosmosProvider.d.ts +57 -0
- package/dist/BBNCosmosProvider.js +55 -0
- package/dist/OnekeyCosmosProvider.d.ts +6 -0
- package/dist/OnekeyCosmosProvider.js +19 -0
- package/dist/cjs/BBNCosmosProvider.js +59 -0
- package/dist/cjs/OnekeyCosmosProvider.js +19 -0
- package/dist/cjs/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/cosmjs.d.ts +2 -1
- package/package.json +9 -8
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ProviderCosmos } from './OnekeyCosmosProvider';
|
|
2
|
+
import { OfflineAminoSigner, OfflineDirectSigner } from './types';
|
|
3
|
+
export type PolkadotRequest = {
|
|
4
|
+
babylonConnectWallet: () => Promise<string>;
|
|
5
|
+
};
|
|
6
|
+
export interface IProviderBBNCosmos {
|
|
7
|
+
/**
|
|
8
|
+
* Connects to the wallet and returns the instance of the wallet provider.
|
|
9
|
+
* @returns A promise that resolves to an instance of the wrapper wallet provider.
|
|
10
|
+
* @throws An error if the wallet is not installed or if connection fails.
|
|
11
|
+
*/
|
|
12
|
+
connectWallet(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the address of the connected wallet.
|
|
15
|
+
* @returns A promise that resolves to the address of the connected wallet.
|
|
16
|
+
*/
|
|
17
|
+
getAddress(): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the public key of the connected wallet.
|
|
20
|
+
* @returns A promise that resolves to the public key of the connected wallet.
|
|
21
|
+
*/
|
|
22
|
+
getPublicKeyHex(): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the name of the wallet provider.
|
|
25
|
+
* @returns A promise that resolves to the name of the wallet provider.
|
|
26
|
+
*/
|
|
27
|
+
getWalletProviderName(): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the icon of the wallet provider.
|
|
30
|
+
* @returns A promise that resolves to the icon of the wallet provider.
|
|
31
|
+
*/
|
|
32
|
+
getWalletProviderIcon(): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves an offline signer that supports both Amino and Direct signing methods.
|
|
35
|
+
* This signer is used for signing transactions offline before broadcasting them to the network.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<OfflineAminoSigner & OfflineDirectSigner>} A promise that resolves to a signer supporting both Amino and Direct signing
|
|
38
|
+
* @throws {Error} If wallet connection is not established or signer cannot be retrieved
|
|
39
|
+
*/
|
|
40
|
+
getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>;
|
|
41
|
+
}
|
|
42
|
+
export declare class BBNProviderCosmos implements IProviderBBNCosmos {
|
|
43
|
+
_provider: ProviderCosmos;
|
|
44
|
+
_state: {
|
|
45
|
+
chainId?: string;
|
|
46
|
+
logo?: string;
|
|
47
|
+
};
|
|
48
|
+
constructor(provider: ProviderCosmos, walletInfo: {
|
|
49
|
+
logo: string;
|
|
50
|
+
});
|
|
51
|
+
connectWallet(): Promise<void>;
|
|
52
|
+
getAddress(): Promise<string>;
|
|
53
|
+
getPublicKeyHex(): Promise<string>;
|
|
54
|
+
getWalletProviderName(): Promise<string>;
|
|
55
|
+
getWalletProviderIcon(): Promise<string>;
|
|
56
|
+
getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export class BBNProviderCosmos {
|
|
11
|
+
constructor(provider, walletInfo) {
|
|
12
|
+
this._state = {};
|
|
13
|
+
this._provider = provider;
|
|
14
|
+
this._state = {
|
|
15
|
+
logo: walletInfo.logo,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
connectWallet() {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const chainId = yield this._provider.babylonConnectWallet();
|
|
21
|
+
this._state.chainId = chainId;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
getAddress() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const account = yield this._provider.babylonGetKey();
|
|
27
|
+
if (!account) {
|
|
28
|
+
throw new Error('No account found');
|
|
29
|
+
}
|
|
30
|
+
return Promise.resolve(account.bech32Address);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getPublicKeyHex() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const account = yield this._provider.babylonGetKey();
|
|
36
|
+
if (!account) {
|
|
37
|
+
throw new Error('No account found');
|
|
38
|
+
}
|
|
39
|
+
return Promise.resolve(Buffer.from(account.pubKey).toString('hex'));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
getWalletProviderName() {
|
|
43
|
+
return Promise.resolve('OneKey');
|
|
44
|
+
}
|
|
45
|
+
getWalletProviderIcon() {
|
|
46
|
+
var _a;
|
|
47
|
+
return Promise.resolve((_a = this._state.logo) !== null && _a !== void 0 ? _a : '');
|
|
48
|
+
}
|
|
49
|
+
getOfflineSigner() {
|
|
50
|
+
if (!this._state.chainId) {
|
|
51
|
+
throw new Error('Need connect wallet first');
|
|
52
|
+
}
|
|
53
|
+
return Promise.resolve(this._provider.getOfflineSigner(this._state.chainId));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -17,6 +17,8 @@ type CosmosProviderEventsMap = {
|
|
|
17
17
|
[PROVIDER_EVENTS.message_low_level]: (payload: IJsonRpcRequest) => void;
|
|
18
18
|
};
|
|
19
19
|
export type CosmosRequest = {
|
|
20
|
+
'babylonConnectWallet': () => Promise<string>;
|
|
21
|
+
'babylonGetKey': () => Promise<KeyHex>;
|
|
20
22
|
'enable': (chainIds: string[]) => Promise<void>;
|
|
21
23
|
'disconnect': (chainIds: string[]) => Promise<void>;
|
|
22
24
|
'experimentalSuggestChain': (chain: any) => Promise<void>;
|
|
@@ -44,6 +46,8 @@ export interface IProviderCosmos {
|
|
|
44
46
|
readonly mode: KeplrMode;
|
|
45
47
|
defaultOptions: KeplrIntereactionOptions;
|
|
46
48
|
enable(chainIds: string | string[]): Promise<void>;
|
|
49
|
+
babylonConnectWallet(): Promise<string>;
|
|
50
|
+
babylonGetKey(): Promise<Key>;
|
|
47
51
|
getKey(chainId: string): Promise<Key>;
|
|
48
52
|
experimentalSuggestChain(chain: any): Promise<void>;
|
|
49
53
|
signAmino(chainId: string, signer: string, signDoc: StdSignDoc, signOptions?: KeplrSignOptions): Promise<AminoSignResponse>;
|
|
@@ -86,6 +90,8 @@ declare class ProviderCosmos extends ProviderCosmosBase implements IProviderCosm
|
|
|
86
90
|
on<E extends keyof CosmosProviderEventsMap>(event: E, listener: CosmosProviderEventsMap[E]): this;
|
|
87
91
|
emit<E extends keyof CosmosProviderEventsMap>(event: E, ...args: Parameters<CosmosProviderEventsMap[E]>): boolean;
|
|
88
92
|
enable(chainIds: string | string[]): Promise<void>;
|
|
93
|
+
babylonConnectWallet(): Promise<string>;
|
|
94
|
+
babylonGetKey(): Promise<Key>;
|
|
89
95
|
disconnect(): Promise<void>;
|
|
90
96
|
getKey(chainId: string): Promise<Key>;
|
|
91
97
|
ping(): Promise<void>;
|
|
@@ -149,6 +149,25 @@ class ProviderCosmos extends ProviderCosmosBase {
|
|
|
149
149
|
params: isArray(chainIds) ? chainIds : [chainIds],
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
|
+
babylonConnectWallet() {
|
|
153
|
+
return this._callBridge({
|
|
154
|
+
method: 'babylonConnectWallet',
|
|
155
|
+
params: undefined,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
babylonGetKey() {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const key = yield this._callBridge({
|
|
161
|
+
method: 'babylonGetKey',
|
|
162
|
+
params: undefined,
|
|
163
|
+
});
|
|
164
|
+
return Object.assign(Object.assign({}, key), {
|
|
165
|
+
// @ts-expect-error
|
|
166
|
+
pubKey: hexToBytes(key.pubKey),
|
|
167
|
+
// @ts-expect-error
|
|
168
|
+
address: hexToBytes(key.address) });
|
|
169
|
+
});
|
|
170
|
+
}
|
|
152
171
|
disconnect() {
|
|
153
172
|
return this._callBridge({
|
|
154
173
|
method: 'disconnect',
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BBNProviderCosmos = void 0;
|
|
13
|
+
class BBNProviderCosmos {
|
|
14
|
+
constructor(provider, walletInfo) {
|
|
15
|
+
this._state = {};
|
|
16
|
+
this._provider = provider;
|
|
17
|
+
this._state = {
|
|
18
|
+
logo: walletInfo.logo,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
connectWallet() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const chainId = yield this._provider.babylonConnectWallet();
|
|
24
|
+
this._state.chainId = chainId;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getAddress() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const account = yield this._provider.babylonGetKey();
|
|
30
|
+
if (!account) {
|
|
31
|
+
throw new Error('No account found');
|
|
32
|
+
}
|
|
33
|
+
return Promise.resolve(account.bech32Address);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getPublicKeyHex() {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const account = yield this._provider.babylonGetKey();
|
|
39
|
+
if (!account) {
|
|
40
|
+
throw new Error('No account found');
|
|
41
|
+
}
|
|
42
|
+
return Promise.resolve(Buffer.from(account.pubKey).toString('hex'));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
getWalletProviderName() {
|
|
46
|
+
return Promise.resolve('OneKey');
|
|
47
|
+
}
|
|
48
|
+
getWalletProviderIcon() {
|
|
49
|
+
var _a;
|
|
50
|
+
return Promise.resolve((_a = this._state.logo) !== null && _a !== void 0 ? _a : '');
|
|
51
|
+
}
|
|
52
|
+
getOfflineSigner() {
|
|
53
|
+
if (!this._state.chainId) {
|
|
54
|
+
throw new Error('Need connect wallet first');
|
|
55
|
+
}
|
|
56
|
+
return Promise.resolve(this._provider.getOfflineSigner(this._state.chainId));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.BBNProviderCosmos = BBNProviderCosmos;
|
|
@@ -155,6 +155,25 @@ class ProviderCosmos extends ProviderCosmosBase_1.ProviderCosmosBase {
|
|
|
155
155
|
params: (0, lodash_es_1.isArray)(chainIds) ? chainIds : [chainIds],
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
|
+
babylonConnectWallet() {
|
|
159
|
+
return this._callBridge({
|
|
160
|
+
method: 'babylonConnectWallet',
|
|
161
|
+
params: undefined,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
babylonGetKey() {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
const key = yield this._callBridge({
|
|
167
|
+
method: 'babylonGetKey',
|
|
168
|
+
params: undefined,
|
|
169
|
+
});
|
|
170
|
+
return Object.assign(Object.assign({}, key), {
|
|
171
|
+
// @ts-expect-error
|
|
172
|
+
pubKey: (0, utils_1.hexToBytes)(key.pubKey),
|
|
173
|
+
// @ts-expect-error
|
|
174
|
+
address: (0, utils_1.hexToBytes)(key.address) });
|
|
175
|
+
});
|
|
176
|
+
}
|
|
158
177
|
disconnect() {
|
|
159
178
|
return this._callBridge({
|
|
160
179
|
method: 'disconnect',
|
package/dist/cjs/index.js
CHANGED
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./OnekeyCosmosProvider"), exports);
|
|
18
18
|
__exportStar(require("./ProviderCosmosBase"), exports);
|
|
19
19
|
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./BBNCosmosProvider"), exports);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types/cosmjs.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Long from 'long';
|
|
1
2
|
export declare enum BroadcastMode {
|
|
2
3
|
/** Return after tx commit */
|
|
3
4
|
Block = "block",
|
|
@@ -66,7 +67,7 @@ export interface SignDoc {
|
|
|
66
67
|
*/
|
|
67
68
|
chainId: string;
|
|
68
69
|
/** account_number is the account number of the account in state */
|
|
69
|
-
accountNumber:
|
|
70
|
+
accountNumber: Long;
|
|
70
71
|
}
|
|
71
72
|
export type SignDocHex = {
|
|
72
73
|
bodyBytes: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/onekey-cosmos-provider",
|
|
3
|
-
"version": "2.2.7-alpha.
|
|
3
|
+
"version": "2.2.7-alpha.4",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -29,17 +29,18 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@noble/hashes": "^1.3.0",
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-core": "2.2.7-alpha.
|
|
33
|
-
"@onekeyfe/cross-inpage-provider-errors": "2.2.7-alpha.
|
|
34
|
-
"@onekeyfe/cross-inpage-provider-types": "2.2.7-alpha.
|
|
35
|
-
"@onekeyfe/extension-bridge-injected": "2.2.7-alpha.
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-core": "2.2.7-alpha.4",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-errors": "2.2.7-alpha.4",
|
|
34
|
+
"@onekeyfe/cross-inpage-provider-types": "2.2.7-alpha.4",
|
|
35
|
+
"@onekeyfe/extension-bridge-injected": "2.2.7-alpha.4",
|
|
36
36
|
"eth-rpc-errors": "^4.0.3",
|
|
37
37
|
"lodash-es": "^4.17.21",
|
|
38
|
-
"long": "^
|
|
38
|
+
"long": "^4.0.0",
|
|
39
39
|
"mitt": "^3.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/lodash-es": "^4.17.12"
|
|
42
|
+
"@types/lodash-es": "^4.17.12",
|
|
43
|
+
"@types/long": "^4.0.0"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "bf2d89c3891145dacea941ba89c6403558661f7d"
|
|
45
46
|
}
|