carbon-js-sdk 0.10.5 → 0.10.6-beta.2
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/lib/provider/keplr/KeplrAccount.js +12 -0
- package/lib/provider/leap/LeapAccount.d.ts +1 -1
- package/lib/provider/leap/LeapAccount.js +10 -0
- package/lib/provider/leap/index.d.ts +1 -1
- package/lib/provider/metamask/MetaMask.js +4 -0
- package/lib/provider/o3/O3Wallet.js +3 -0
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.js +2 -1
- package/lib/util/message.d.ts +2 -0
- package/lib/util/message.js +21 -0
- package/lib/wallet/CarbonSigner.d.ts +9 -3
- package/lib/wallet/CarbonSigner.js +23 -0
- package/lib/wallet/CarbonWallet.d.ts +2 -1
- package/lib/wallet/CarbonWallet.js +3 -0
- package/package.json +2 -2
|
@@ -65,12 +65,18 @@ class KeplrAccount {
|
|
|
65
65
|
throw (error_1.parseEvmError(error));
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
|
+
const signMessage = (address, message) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const chainId = chainInfo.chainId;
|
|
70
|
+
const { signature } = yield keplr.signArbitrary(chainId, address, message);
|
|
71
|
+
return Buffer.from(signature, 'base64').toString('hex');
|
|
72
|
+
});
|
|
68
73
|
return {
|
|
69
74
|
type: wallet_1.CarbonSignerTypes.BrowserInjected,
|
|
70
75
|
signDirect,
|
|
71
76
|
signAmino,
|
|
72
77
|
getAccounts,
|
|
73
78
|
sendEvmTransaction,
|
|
79
|
+
signMessage,
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
82
|
static createKeplrSignerAmino(keplr, chainInfo, account) {
|
|
@@ -105,11 +111,17 @@ class KeplrAccount {
|
|
|
105
111
|
throw (error_1.parseEvmError(error));
|
|
106
112
|
}
|
|
107
113
|
});
|
|
114
|
+
const signMessage = (address, message) => __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const chainId = chainInfo.chainId;
|
|
116
|
+
const { signature } = yield keplr.signArbitrary(chainId, address, message);
|
|
117
|
+
return Buffer.from(signature, 'base64').toString('hex');
|
|
118
|
+
});
|
|
108
119
|
return {
|
|
109
120
|
type: wallet_1.CarbonSignerTypes.BrowserInjected,
|
|
110
121
|
signAmino,
|
|
111
122
|
getAccounts,
|
|
112
123
|
sendEvmTransaction,
|
|
124
|
+
signMessage,
|
|
113
125
|
};
|
|
114
126
|
}
|
|
115
127
|
static queryFeeCurrencies(configProvider) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CarbonSigner } from "../../wallet";
|
|
2
|
-
import { Leap } from "@cosmos-kit/leap";
|
|
2
|
+
import { Leap } from "@cosmos-kit/leap-extension";
|
|
3
3
|
import { AppCurrency, ChainInfo, FeeCurrency } from "@keplr-wallet/types";
|
|
4
4
|
import SDKProvider from "../sdk";
|
|
5
5
|
declare class LeapAccount {
|
|
@@ -47,12 +47,17 @@ class LeapAccount {
|
|
|
47
47
|
const sendEvmTransaction = (api, req) => __awaiter(this, void 0, void 0, function* () {
|
|
48
48
|
throw new Error("signing not available");
|
|
49
49
|
});
|
|
50
|
+
const signMessage = (address, message) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const { signature } = yield leap.signArbitrary(chainId, address, message);
|
|
52
|
+
return Buffer.from(signature, 'base64').toString('hex');
|
|
53
|
+
});
|
|
50
54
|
return {
|
|
51
55
|
type: wallet_1.CarbonSignerTypes.BrowserInjected,
|
|
52
56
|
signDirect,
|
|
53
57
|
signAmino,
|
|
54
58
|
getAccounts,
|
|
55
59
|
sendEvmTransaction,
|
|
60
|
+
signMessage,
|
|
56
61
|
};
|
|
57
62
|
}
|
|
58
63
|
static createLeapSignerAmino(leap, chainId) {
|
|
@@ -75,11 +80,16 @@ class LeapAccount {
|
|
|
75
80
|
const sendEvmTransaction = (api, req) => __awaiter(this, void 0, void 0, function* () {
|
|
76
81
|
throw new Error("signing not available");
|
|
77
82
|
});
|
|
83
|
+
const signMessage = (address, message) => __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const { signature } = yield leap.signArbitrary(chainId, address, message);
|
|
85
|
+
return Buffer.from(signature, 'base64').toString('hex');
|
|
86
|
+
});
|
|
78
87
|
return {
|
|
79
88
|
type: wallet_1.CarbonSignerTypes.BrowserInjected,
|
|
80
89
|
signAmino,
|
|
81
90
|
getAccounts,
|
|
82
91
|
sendEvmTransaction,
|
|
92
|
+
signMessage,
|
|
83
93
|
};
|
|
84
94
|
}
|
|
85
95
|
static getChainId(configProvider) {
|
|
@@ -361,6 +361,9 @@ class MetaMask {
|
|
|
361
361
|
throw (error_1.parseEvmError(error, index_1.ProviderAgent.MetamaskExtension));
|
|
362
362
|
}
|
|
363
363
|
});
|
|
364
|
+
const signMessage = (address, message) => __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
return metamask.personalSign(address, message);
|
|
366
|
+
});
|
|
364
367
|
return {
|
|
365
368
|
type: wallet_1.CarbonSignerTypes.BrowserInjected,
|
|
366
369
|
legacyEip712SignMode: metamask.legacyEip712SignMode,
|
|
@@ -369,6 +372,7 @@ class MetaMask {
|
|
|
369
372
|
getAccounts,
|
|
370
373
|
signLegacyEip712,
|
|
371
374
|
sendEvmTransaction,
|
|
375
|
+
signMessage,
|
|
372
376
|
};
|
|
373
377
|
}
|
|
374
378
|
static getNetworkParams(network, blockchain = 'Ethereum') {
|
package/lib/util/index.d.ts
CHANGED
package/lib/util/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.AllianceUtils = exports.GrantUtils = exports.TypeUtils = exports.CarbonTx = exports.TransferUtils = exports.TokenUtils = exports.NumberUtils = exports.NetworkUtils = exports.IBCUtils = exports.GovUtils = exports.GenericUtils = exports.FetchUtils = exports.ExternalUtils = exports.BlockchainUtils = exports.APIUtils = exports.AddressUtils = void 0;
|
|
22
|
+
exports.MessageUtils = exports.AllianceUtils = exports.GrantUtils = exports.TypeUtils = exports.CarbonTx = exports.TransferUtils = exports.TokenUtils = exports.NumberUtils = exports.NetworkUtils = exports.IBCUtils = exports.GovUtils = exports.GenericUtils = exports.FetchUtils = exports.ExternalUtils = exports.BlockchainUtils = exports.APIUtils = exports.AddressUtils = void 0;
|
|
23
23
|
exports.AddressUtils = __importStar(require("./address"));
|
|
24
24
|
exports.APIUtils = __importStar(require("./api"));
|
|
25
25
|
exports.BlockchainUtils = __importStar(require("./blockchain"));
|
|
@@ -36,3 +36,4 @@ exports.CarbonTx = __importStar(require("./tx"));
|
|
|
36
36
|
exports.TypeUtils = __importStar(require("./type"));
|
|
37
37
|
exports.GrantUtils = __importStar(require("./grant"));
|
|
38
38
|
exports.AllianceUtils = __importStar(require("./alliance"));
|
|
39
|
+
exports.MessageUtils = __importStar(require("./message"));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constructAdr36SignDoc = void 0;
|
|
4
|
+
const constructAdr36SignDoc = (address, message) => {
|
|
5
|
+
const msgSignData = { signer: address, data: Buffer.from(message).toString('base64') };
|
|
6
|
+
const msgs = [{ type: 'sign/MsgSignData', value: msgSignData }];
|
|
7
|
+
const fee = {
|
|
8
|
+
gas: '0',
|
|
9
|
+
amount: [],
|
|
10
|
+
};
|
|
11
|
+
const signDoc = {
|
|
12
|
+
chain_id: '',
|
|
13
|
+
account_number: '0',
|
|
14
|
+
sequence: '0',
|
|
15
|
+
fee,
|
|
16
|
+
msgs,
|
|
17
|
+
memo: '',
|
|
18
|
+
};
|
|
19
|
+
return signDoc;
|
|
20
|
+
};
|
|
21
|
+
exports.constructAdr36SignDoc = constructAdr36SignDoc;
|
|
@@ -14,16 +14,19 @@ export declare enum CarbonSignerTypes {
|
|
|
14
14
|
export interface EvmSigner {
|
|
15
15
|
readonly sendEvmTransaction: (api: CarbonSDK, req: ethers.providers.TransactionRequest) => Promise<string>;
|
|
16
16
|
}
|
|
17
|
+
export interface ArbitraryMessageSigner {
|
|
18
|
+
readonly signMessage: (address: string, message: string) => Promise<string>;
|
|
19
|
+
}
|
|
17
20
|
export interface EIP712Signer extends EvmSigner {
|
|
18
21
|
legacyEip712SignMode: boolean;
|
|
19
22
|
readonly signLegacyEip712: (signerAddress: string, signDoc: StdSignDoc) => Promise<LegacyEIP712AminoSignResponse>;
|
|
20
23
|
}
|
|
21
24
|
export declare type CarbonSigner = DirectCarbonSigner | AminoCarbonSigner | CarbonEIP712Signer;
|
|
22
|
-
export declare type CarbonEIP712Signer = (DirectCarbonSigner | AminoCarbonSigner) & EIP712Signer;
|
|
23
|
-
export declare type DirectCarbonSigner = OfflineDirectSigner & EvmSigner & {
|
|
25
|
+
export declare type CarbonEIP712Signer = (DirectCarbonSigner | AminoCarbonSigner) & EIP712Signer & ArbitraryMessageSigner;
|
|
26
|
+
export declare type DirectCarbonSigner = OfflineDirectSigner & EvmSigner & ArbitraryMessageSigner & {
|
|
24
27
|
type: CarbonSignerTypes;
|
|
25
28
|
};
|
|
26
|
-
export declare type AminoCarbonSigner = OfflineAminoSigner & EvmSigner & {
|
|
29
|
+
export declare type AminoCarbonSigner = OfflineAminoSigner & EvmSigner & ArbitraryMessageSigner & {
|
|
27
30
|
type: CarbonSignerTypes;
|
|
28
31
|
};
|
|
29
32
|
export declare type LegacyEIP712AminoSignResponse = AminoSignResponse & {
|
|
@@ -43,12 +46,14 @@ export declare class CarbonPrivateKeySigner implements DirectCarbonSigner, Amino
|
|
|
43
46
|
signAmino(signerAddress: string, signDoc: StdSignDoc): Promise<AminoSignResponse>;
|
|
44
47
|
signDirect(signerAddress: string, signDoc: SignDoc): Promise<DirectSignResponse>;
|
|
45
48
|
sendEvmTransaction(api: CarbonSDK, req: ethers.providers.TransactionRequest): Promise<string>;
|
|
49
|
+
signMessage(address: string, message: string): Promise<string>;
|
|
46
50
|
}
|
|
47
51
|
export declare class CarbonNonSigner implements DirectCarbonSigner {
|
|
48
52
|
type: CarbonSignerTypes;
|
|
49
53
|
getAccounts(): Promise<readonly AccountData[]>;
|
|
50
54
|
signDirect(): Promise<DirectSignResponse>;
|
|
51
55
|
sendEvmTransaction(api: CarbonSDK, req: ethers.providers.TransactionRequest): Promise<string>;
|
|
56
|
+
signMessage(address: string, message: string): Promise<string>;
|
|
52
57
|
}
|
|
53
58
|
export declare class CarbonLedgerSigner implements AminoCarbonSigner {
|
|
54
59
|
readonly ledger: CosmosLedger;
|
|
@@ -58,5 +63,6 @@ export declare class CarbonLedgerSigner implements AminoCarbonSigner {
|
|
|
58
63
|
getAccounts(): Promise<readonly AccountData[]>;
|
|
59
64
|
signAmino(_: string, doc: StdSignDoc): Promise<AminoSignResponse>;
|
|
60
65
|
sendEvmTransaction(api: CarbonSDK, req: ethers.providers.TransactionRequest): Promise<string>;
|
|
66
|
+
signMessage(_: string, message: string): Promise<string>;
|
|
61
67
|
constructor(ledger: CosmosLedger);
|
|
62
68
|
}
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CarbonLedgerSigner = exports.CarbonNonSigner = exports.CarbonPrivateKeySigner = exports.isCarbonEIP712Signer = exports.CarbonSignerTypes = void 0;
|
|
13
13
|
const generic_1 = require("../util/generic");
|
|
14
|
+
const message_1 = require("../util/message");
|
|
14
15
|
const amino_1 = require("@cosmjs/amino");
|
|
15
16
|
const proto_signing_1 = require("@cosmjs/proto-signing");
|
|
16
17
|
var CarbonSignerTypes;
|
|
@@ -67,6 +68,13 @@ class CarbonPrivateKeySigner {
|
|
|
67
68
|
throw new Error("signing not available");
|
|
68
69
|
});
|
|
69
70
|
}
|
|
71
|
+
signMessage(address, message) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const aminoWallet = yield this.initAminoWallet();
|
|
74
|
+
const signedDoc = yield aminoWallet.signAmino(address, message_1.constructAdr36SignDoc(address, message));
|
|
75
|
+
return Buffer.from(signedDoc.signature.signature, 'base64').toString('hex');
|
|
76
|
+
});
|
|
77
|
+
}
|
|
70
78
|
}
|
|
71
79
|
exports.CarbonPrivateKeySigner = CarbonPrivateKeySigner;
|
|
72
80
|
class CarbonNonSigner {
|
|
@@ -88,6 +96,11 @@ class CarbonNonSigner {
|
|
|
88
96
|
throw new Error("signing not available");
|
|
89
97
|
});
|
|
90
98
|
}
|
|
99
|
+
signMessage(address, message) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
throw new Error("signing not available");
|
|
102
|
+
});
|
|
103
|
+
}
|
|
91
104
|
}
|
|
92
105
|
exports.CarbonNonSigner = CarbonNonSigner;
|
|
93
106
|
// Uses amino because ledger does not work with protobuf yet
|
|
@@ -134,5 +147,15 @@ class CarbonLedgerSigner {
|
|
|
134
147
|
throw new Error("signing not available");
|
|
135
148
|
});
|
|
136
149
|
}
|
|
150
|
+
signMessage(_, message) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const account = yield this.retrieveAccount();
|
|
153
|
+
const { pubkey, address } = account;
|
|
154
|
+
const doc = JSON.stringify(message_1.constructAdr36SignDoc(address, message));
|
|
155
|
+
const signBytes = yield this.ledger.sign(doc);
|
|
156
|
+
const { signature } = amino_1.encodeSecp256k1Signature(pubkey, signBytes);
|
|
157
|
+
return Buffer.from(signature, 'base64').toString('hex');
|
|
158
|
+
});
|
|
159
|
+
}
|
|
137
160
|
}
|
|
138
161
|
exports.CarbonLedgerSigner = CarbonLedgerSigner;
|
|
@@ -15,7 +15,7 @@ import { Account, DeliverTxResponse } from "@cosmjs/stargate";
|
|
|
15
15
|
import { Tendermint37Client } from "@cosmjs/tendermint-rpc";
|
|
16
16
|
import { BroadcastTxAsyncResponse, BroadcastTxSyncResponse, TxResponse } from "@cosmjs/tendermint-rpc/build/tendermint37/responses";
|
|
17
17
|
import { Key as LeapKey } from "@cosmos-kit/core";
|
|
18
|
-
import { Leap } from "@cosmos-kit/leap";
|
|
18
|
+
import { Leap } from "@cosmos-kit/leap-extension";
|
|
19
19
|
import { Key } from "@keplr-wallet/types";
|
|
20
20
|
import { TxRaw as StargateTxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
21
21
|
import { CarbonSigner, CarbonSignerTypes } from "./CarbonSigner";
|
|
@@ -185,6 +185,7 @@ export declare class CarbonWallet {
|
|
|
185
185
|
isLedgerViaBrowserExtension(): boolean;
|
|
186
186
|
isPrivateKeySigner(): boolean;
|
|
187
187
|
isBrowserInjectedSigner(): boolean;
|
|
188
|
+
isNonSigner(): boolean;
|
|
188
189
|
isSmartWalletEnabled(): boolean;
|
|
189
190
|
getSmartWalletPrivateKey(blockchain?: SmartWalletBlockchain): Buffer | null;
|
|
190
191
|
reconnectTmClient(fallbackConfig: OverrideConfig | null): Promise<void>;
|
|
@@ -599,6 +599,9 @@ class CarbonWallet {
|
|
|
599
599
|
isBrowserInjectedSigner() {
|
|
600
600
|
return this.isSigner(CarbonSigner_1.CarbonSignerTypes.BrowserInjected);
|
|
601
601
|
}
|
|
602
|
+
isNonSigner() {
|
|
603
|
+
return this.isSigner(CarbonSigner_1.CarbonSignerTypes.PublicKey);
|
|
604
|
+
}
|
|
602
605
|
isSmartWalletEnabled() {
|
|
603
606
|
return !!(this.mnemonic || this.privateKey);
|
|
604
607
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-js-sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.6-beta.2",
|
|
4
4
|
"description": "TypeScript SDK for Carbon blockchain",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@cityofzion/neon-core-next": "npm:@cityofzion/neon-core@^5.0.0",
|
|
42
42
|
"@cityofzion/neon-js": "^4.9.0",
|
|
43
43
|
"@cosmjs/stargate": "~0.31.3",
|
|
44
|
-
"@cosmos-kit/leap": "^0.
|
|
44
|
+
"@cosmos-kit/leap": "^0.15.12",
|
|
45
45
|
"@improbable-eng/grpc-web": "^0.15.0",
|
|
46
46
|
"@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
|
|
47
47
|
"@keplr-wallet/types": "^0.11.64",
|