@keplr-wallet/cosmos 0.10.0 → 0.10.1
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/build/stargate/codec/index.d.ts +15 -9
- package/build/stargate/codec/index.js +16 -13
- package/build/stargate/codec/index.js.map +1 -1
- package/build/stargate/codec/unknown.d.ts +2 -1
- package/build/stargate/codec/unknown.js.map +1 -1
- package/build/stargate/decoder/decode.spec.js +4 -1
- package/build/stargate/decoder/decode.spec.js.map +1 -1
- package/build/stargate/decoder/index.d.ts +7 -8
- package/build/stargate/decoder/index.js +14 -9
- package/build/stargate/decoder/index.js.map +1 -1
- package/build/stargate/index.d.ts +0 -1
- package/build/stargate/index.js +0 -1
- package/build/stargate/index.js.map +1 -1
- package/build/stargate/wrapper/index.d.ts +4 -4
- package/build/stargate/wrapper/index.js +9 -4
- package/build/stargate/wrapper/index.js.map +1 -1
- package/package.json +9 -9
- package/src/stargate/codec/index.ts +38 -30
- package/src/stargate/codec/unknown.ts +2 -1
- package/src/stargate/decoder/decode.spec.ts +5 -2
- package/src/stargate/decoder/index.ts +30 -19
- package/src/stargate/index.ts +0 -1
- package/src/stargate/wrapper/index.ts +9 -8
- package/build/stargate/proto/generated/codecimpl.d.ts +0 -3695
- package/build/stargate/proto/generated/codecimpl.js +0 -4221
- package/build/stargate/proto/index.d.ts +0 -1
- package/build/stargate/proto/index.js +0 -21
- package/build/stargate/proto/index.js.map +0 -1
- package/src/stargate/proto/generated/codecimpl.d.ts +0 -3695
- package/src/stargate/proto/generated/codecimpl.js +0 -4221
- package/src/stargate/proto/index.ts +0 -7
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import { google } from "../proto";
|
|
2
1
|
import * as $protobuf from "protobufjs";
|
|
2
|
+
import { Any } from "@keplr-wallet/proto-types/google/protobuf/any";
|
|
3
3
|
export * from "./unknown";
|
|
4
|
+
export declare type AnyWithUnpacked = Any | (Any & {
|
|
5
|
+
unpacked: unknown;
|
|
6
|
+
factory: ProtoFactory;
|
|
7
|
+
});
|
|
8
|
+
interface ProtoFactory {
|
|
9
|
+
encode: (message: any, writer?: $protobuf.Writer) => $protobuf.Writer;
|
|
10
|
+
decode: (r: $protobuf.Reader | Uint8Array, l?: number) => any;
|
|
11
|
+
fromJSON: (object: any) => any;
|
|
12
|
+
toJSON: (message: any) => unknown;
|
|
13
|
+
}
|
|
4
14
|
export declare class ProtoCodec {
|
|
5
|
-
protected typeUrlMap: Map<string,
|
|
6
|
-
decode: (r: $protobuf.Reader | Uint8Array, l?: number) => any;
|
|
7
|
-
}>;
|
|
15
|
+
protected typeUrlMap: Map<string, ProtoFactory>;
|
|
8
16
|
/**
|
|
9
17
|
* Unpack the any to the registered message.
|
|
10
18
|
* NOTE: If there is no matched message, it will not throw an error but return the `UnknownMessage` class.
|
|
11
|
-
* @param
|
|
19
|
+
* @param any
|
|
12
20
|
*/
|
|
13
|
-
unpackAny(
|
|
14
|
-
registerAny(typeUrl: string, message:
|
|
15
|
-
decode: (r: $protobuf.Reader | Uint8Array, l?: number) => any;
|
|
16
|
-
}): void;
|
|
21
|
+
unpackAny(any: Any): AnyWithUnpacked;
|
|
22
|
+
registerAny(typeUrl: string, message: ProtoFactory): void;
|
|
17
23
|
}
|
|
18
24
|
export declare const defaultProtoCodec: ProtoCodec;
|
|
@@ -11,8 +11,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.defaultProtoCodec = exports.ProtoCodec = void 0;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const tx_1 = require("@keplr-wallet/proto-types/cosmos/bank/v1beta1/tx");
|
|
15
|
+
const tx_2 = require("@keplr-wallet/proto-types/cosmos/staking/v1beta1/tx");
|
|
16
|
+
const tx_3 = require("@keplr-wallet/proto-types/cosmwasm/wasm/v1/tx");
|
|
16
17
|
const unknown_1 = require("./unknown");
|
|
17
18
|
__exportStar(require("./unknown"), exports);
|
|
18
19
|
class ProtoCodec {
|
|
@@ -22,15 +23,17 @@ class ProtoCodec {
|
|
|
22
23
|
/**
|
|
23
24
|
* Unpack the any to the registered message.
|
|
24
25
|
* NOTE: If there is no matched message, it will not throw an error but return the `UnknownMessage` class.
|
|
25
|
-
* @param
|
|
26
|
+
* @param any
|
|
26
27
|
*/
|
|
27
|
-
unpackAny(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return new unknown_1.UnknownMessage(any.type_url, any.value);
|
|
28
|
+
unpackAny(any) {
|
|
29
|
+
if (!this.typeUrlMap.has(any.typeUrl)) {
|
|
30
|
+
return new unknown_1.UnknownMessage(any.typeUrl, any.value);
|
|
31
31
|
}
|
|
32
32
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
33
|
-
|
|
33
|
+
const factory = this.typeUrlMap.get(any.typeUrl);
|
|
34
|
+
const unpacked = factory.decode(any.value);
|
|
35
|
+
return Object.assign(Object.assign({}, any), { unpacked,
|
|
36
|
+
factory });
|
|
34
37
|
}
|
|
35
38
|
registerAny(typeUrl, message) {
|
|
36
39
|
this.typeUrlMap.set(typeUrl, message);
|
|
@@ -38,9 +41,9 @@ class ProtoCodec {
|
|
|
38
41
|
}
|
|
39
42
|
exports.ProtoCodec = ProtoCodec;
|
|
40
43
|
exports.defaultProtoCodec = new ProtoCodec();
|
|
41
|
-
exports.defaultProtoCodec.registerAny("/cosmos.bank.v1beta1.MsgSend",
|
|
42
|
-
exports.defaultProtoCodec.registerAny("/cosmos.staking.v1beta1.MsgDelegate",
|
|
43
|
-
exports.defaultProtoCodec.registerAny("/cosmos.staking.v1beta1.MsgUndelegate",
|
|
44
|
-
exports.defaultProtoCodec.registerAny("/cosmos.staking.v1beta1.MsgBeginRedelegate",
|
|
45
|
-
exports.defaultProtoCodec.registerAny("/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
44
|
+
exports.defaultProtoCodec.registerAny("/cosmos.bank.v1beta1.MsgSend", tx_1.MsgSend);
|
|
45
|
+
exports.defaultProtoCodec.registerAny("/cosmos.staking.v1beta1.MsgDelegate", tx_2.MsgDelegate);
|
|
46
|
+
exports.defaultProtoCodec.registerAny("/cosmos.staking.v1beta1.MsgUndelegate", tx_2.MsgUndelegate);
|
|
47
|
+
exports.defaultProtoCodec.registerAny("/cosmos.staking.v1beta1.MsgBeginRedelegate", tx_2.MsgBeginRedelegate);
|
|
48
|
+
exports.defaultProtoCodec.registerAny("/cosmwasm.wasm.v1.MsgExecuteContract", tx_3.MsgExecuteContract);
|
|
46
49
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stargate/codec/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stargate/codec/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,yEAA2E;AAC3E,4EAI6D;AAC7D,sEAAmF;AACnF,uCAA2C;AAE3C,4CAA0B;AAa1B,MAAa,UAAU;IAAvB;QACY,eAAU,GAA8B,IAAI,GAAG,EAAE,CAAC;IA0B9D,CAAC;IAxBC;;;;OAIG;IACH,SAAS,CAAC,GAAQ;QAChB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YACrC,OAAO,IAAI,wBAAc,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;SACnD;QAED,oEAAoE;QACpE,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAE,CAAC;QAClD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAE3C,uCACK,GAAG,KACN,QAAQ;YACR,OAAO,IACP;IACJ,CAAC;IAED,WAAW,CAAC,OAAe,EAAE,OAAqB;QAChD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;CACF;AA3BD,gCA2BC;AAEY,QAAA,iBAAiB,GAAG,IAAI,UAAU,EAAE,CAAC;AAClD,yBAAiB,CAAC,WAAW,CAAC,8BAA8B,EAAE,YAAO,CAAC,CAAC;AACvE,yBAAiB,CAAC,WAAW,CAC3B,qCAAqC,EACrC,gBAAW,CACZ,CAAC;AACF,yBAAiB,CAAC,WAAW,CAC3B,uCAAuC,EACvC,kBAAa,CACd,CAAC;AACF,yBAAiB,CAAC,WAAW,CAC3B,4CAA4C,EAC5C,uBAAkB,CACnB,CAAC;AACF,yBAAiB,CAAC,WAAW,CAC3B,sCAAsC,EACtC,uBAAkB,CACnB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../src/stargate/codec/unknown.ts"],"names":[],"mappings":";;;AAAA,oCAAiC;
|
|
1
|
+
{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../src/stargate/codec/unknown.ts"],"names":[],"mappings":";;;AAAA,oCAAiC;AAGjC,MAAa,cAAc;IACzB;IACE,oBAAoB;IACD,QAAgB;IACnC,iBAAiB;IACE,MAAkB;QAFlB,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,WAAM,GAAN,MAAM,CAAY;IACpC,CAAC;IAEJ,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,MAAM;QACJ,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,eAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;SACnD,CAAC;IACJ,CAAC;CACF;AAtBD,wCAsBC"}
|
|
@@ -74,7 +74,10 @@ d701a0c0a057374616b65120331303012580a500a460a1f2f636f736d6f732e63727970746f2e736
|
|
|
74
74
|
assert_1.default.strictEqual(signDoc.chainId, "test");
|
|
75
75
|
assert_1.default.strictEqual(signDoc.accountNumber, "1");
|
|
76
76
|
assert_1.default.strictEqual(signDoc.txMsgs.length, 1);
|
|
77
|
-
|
|
77
|
+
if (!("unpacked" in signDoc.txMsgs[0])) {
|
|
78
|
+
throw new Error("Msgs not parsed properly");
|
|
79
|
+
}
|
|
80
|
+
const msg = signDoc.txMsgs[0].unpacked;
|
|
78
81
|
assert_1.default.strictEqual(msg.fromAddress, "cosmos1xesvkr6d0j96j5zdcw5fmqxavjvuvqx2ygy7mp");
|
|
79
82
|
assert_1.default.strictEqual(msg.toAddress, "cosmos1xesvkr6d0j96j5zdcw5fmqxavjvuvqx2ygy7mp");
|
|
80
83
|
assert_1.default.strictEqual(msg.amount[0].denom, "stake");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.spec.js","sourceRoot":"","sources":["../../../src/stargate/decoder/decode.spec.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,mCAA8C;AAI9C,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,EAAE,CAAC,wBAAwB,EAAE;QAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAuDG;;QAEH,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CACvB;;;;;sDAKgD,EAChD,KAAK,CACN,CAAC;QAEF,MAAM,OAAO,GAAG,2BAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAElD,gBAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5C,gBAAM,CAAC,WAAW,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAE/C,gBAAM,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,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GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAEhD,gBAAM,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5C,gBAAM,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAC;QAEjE,gBAAM,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC3D,gBAAM,CAAC,WAAW,OAChB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,0CAAE,QAAQ,IAClD,GAAG,CACJ,CAAC;QACF,gBAAM,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,EAAE,IAAI,CAAC,CAAC;QACvD,gBAAM,CAAC,WAAW,OAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,0CAAE,OAAO,EAAE,EAAE,CAAC,CAAC;QACtD,gBAAM,CAAC,WAAW,OAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,0CAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { ProtoCodec } from "../codec";
|
|
1
|
+
import { SignDoc, TxBody, AuthInfo } from "@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx";
|
|
2
|
+
import { AnyWithUnpacked, ProtoCodec } from "../codec";
|
|
4
3
|
export declare class ProtoSignDocDecoder {
|
|
5
4
|
readonly signDoc: SignDoc;
|
|
6
5
|
protected readonly protoCodec: ProtoCodec;
|
|
7
6
|
static decode(bytes: Uint8Array): ProtoSignDocDecoder;
|
|
8
|
-
protected _txBody?:
|
|
9
|
-
protected _authInfo?:
|
|
7
|
+
protected _txBody?: TxBody;
|
|
8
|
+
protected _authInfo?: AuthInfo;
|
|
10
9
|
constructor(signDoc: SignDoc, protoCodec?: ProtoCodec);
|
|
11
|
-
get txBody():
|
|
12
|
-
get txMsgs():
|
|
13
|
-
get authInfo():
|
|
10
|
+
get txBody(): TxBody;
|
|
11
|
+
get txMsgs(): AnyWithUnpacked[];
|
|
12
|
+
get authInfo(): AuthInfo;
|
|
14
13
|
get chainId(): string;
|
|
15
14
|
get accountNumber(): string;
|
|
16
15
|
toBytes(): Uint8Array;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ProtoSignDocDecoder = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tx_1 = require("@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx");
|
|
5
5
|
const codec_1 = require("../codec");
|
|
6
6
|
class ProtoSignDocDecoder {
|
|
7
7
|
constructor(signDoc, protoCodec = codec_1.defaultProtoCodec) {
|
|
@@ -9,11 +9,11 @@ class ProtoSignDocDecoder {
|
|
|
9
9
|
this.protoCodec = protoCodec;
|
|
10
10
|
}
|
|
11
11
|
static decode(bytes) {
|
|
12
|
-
return new ProtoSignDocDecoder(
|
|
12
|
+
return new ProtoSignDocDecoder(tx_1.SignDoc.decode(bytes));
|
|
13
13
|
}
|
|
14
14
|
get txBody() {
|
|
15
15
|
if (!this._txBody) {
|
|
16
|
-
this._txBody =
|
|
16
|
+
this._txBody = tx_1.TxBody.decode(this.signDoc.bodyBytes);
|
|
17
17
|
}
|
|
18
18
|
return this._txBody;
|
|
19
19
|
}
|
|
@@ -26,7 +26,7 @@ class ProtoSignDocDecoder {
|
|
|
26
26
|
}
|
|
27
27
|
get authInfo() {
|
|
28
28
|
if (!this._authInfo) {
|
|
29
|
-
this._authInfo =
|
|
29
|
+
this._authInfo = tx_1.AuthInfo.decode(this.signDoc.authInfoBytes);
|
|
30
30
|
}
|
|
31
31
|
return this._authInfo;
|
|
32
32
|
}
|
|
@@ -37,19 +37,24 @@ class ProtoSignDocDecoder {
|
|
|
37
37
|
return this.signDoc.accountNumber.toString();
|
|
38
38
|
}
|
|
39
39
|
toBytes() {
|
|
40
|
-
return
|
|
40
|
+
return tx_1.SignDoc.encode(this.signDoc).finish();
|
|
41
41
|
}
|
|
42
42
|
toJSON() {
|
|
43
43
|
return {
|
|
44
|
-
txBody: Object.assign(Object.assign({},
|
|
44
|
+
txBody: Object.assign(Object.assign({}, tx_1.TxBody.toJSON(this.txBody)), {
|
|
45
45
|
messages: this.txMsgs.map((msg) => {
|
|
46
|
-
if (msg
|
|
47
|
-
|
|
46
|
+
if (msg) {
|
|
47
|
+
if (msg instanceof codec_1.UnknownMessage) {
|
|
48
|
+
return msg.toJSON();
|
|
49
|
+
}
|
|
50
|
+
if ("factory" in msg) {
|
|
51
|
+
return msg.factory.toJSON(msg.unpacked);
|
|
52
|
+
}
|
|
48
53
|
}
|
|
49
54
|
return msg;
|
|
50
55
|
}),
|
|
51
56
|
}),
|
|
52
|
-
authInfo:
|
|
57
|
+
authInfo: tx_1.AuthInfo.toJSON(this.authInfo),
|
|
53
58
|
chainId: this.chainId,
|
|
54
59
|
accountNumber: this.accountNumber,
|
|
55
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stargate/decoder/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stargate/decoder/index.ts"],"names":[],"mappings":";;;AAAA,uEAIwD;AACxD,oCAKkB;AAElB,MAAa,mBAAmB;IAQ9B,YACkB,OAAgB,EACb,aAAyB,yBAAiB;QAD7C,YAAO,GAAP,OAAO,CAAS;QACb,eAAU,GAAV,UAAU,CAAgC;IAC5D,CAAC;IAVG,MAAM,CAAC,MAAM,CAAC,KAAiB;QACpC,OAAO,IAA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IAAI,GAAG,YAAY,sBAAc,EAAE;4BACjC,OAAO,GAAG,CAAC,MAAM,EAAE,CAAC;yBACrB;wBACD,IAAI,SAAS,IAAI,GAAG,EAAE;4BACpB,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;yBACzC;qBACF;oBACD,OAAO,GAAG,CAAC;gBACb,CAAC,CAAC;aACH,CACF;YACD,QAAQ,EAAE,aAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;YACxC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC;IACJ,CAAC;CACF;AAzED,kDAyEC"}
|
package/build/stargate/index.js
CHANGED
|
@@ -11,7 +11,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./codec"), exports);
|
|
14
|
-
__exportStar(require("./proto"), exports);
|
|
15
14
|
__exportStar(require("./decoder"), exports);
|
|
16
15
|
__exportStar(require("./wrapper"), exports);
|
|
17
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stargate/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stargate/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,4CAA0B"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ProtoSignDocDecoder } from "../decoder";
|
|
2
2
|
import { Coin, StdSignDoc } from "@cosmjs/launchpad";
|
|
3
|
-
import {
|
|
3
|
+
import { SignDoc } from "@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx";
|
|
4
4
|
export declare class SignDocWrapper {
|
|
5
|
-
protected readonly signDoc: StdSignDoc |
|
|
5
|
+
protected readonly signDoc: StdSignDoc | SignDoc;
|
|
6
6
|
protected _protoSignDoc?: ProtoSignDocDecoder;
|
|
7
7
|
readonly isADR36SignDoc: boolean;
|
|
8
8
|
readonly mode: "amino" | "direct";
|
|
9
|
-
constructor(signDoc: StdSignDoc |
|
|
9
|
+
constructor(signDoc: StdSignDoc | SignDoc);
|
|
10
10
|
static fromAminoSignDoc(signDoc: StdSignDoc): SignDocWrapper;
|
|
11
|
-
static fromDirectSignDoc(signDoc:
|
|
11
|
+
static fromDirectSignDoc(signDoc: SignDoc): SignDocWrapper;
|
|
12
12
|
static fromDirectSignDocBytes(signDocBytes: Uint8Array): SignDocWrapper;
|
|
13
13
|
clone(): SignDocWrapper;
|
|
14
14
|
get protoSignDoc(): ProtoSignDocDecoder;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SignDocWrapper = void 0;
|
|
4
4
|
const decoder_1 = require("../decoder");
|
|
5
|
-
const
|
|
5
|
+
const tx_1 = require("@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx");
|
|
6
6
|
const adr_36_1 = require("../../adr-36");
|
|
7
7
|
class SignDocWrapper {
|
|
8
8
|
constructor(signDoc) {
|
|
@@ -31,7 +31,7 @@ class SignDocWrapper {
|
|
|
31
31
|
return new SignDocWrapper(signDoc);
|
|
32
32
|
}
|
|
33
33
|
static fromDirectSignDocBytes(signDocBytes) {
|
|
34
|
-
return new SignDocWrapper(
|
|
34
|
+
return new SignDocWrapper(tx_1.SignDoc.decode(signDocBytes));
|
|
35
35
|
}
|
|
36
36
|
clone() {
|
|
37
37
|
return new SignDocWrapper(this.signDoc);
|
|
@@ -87,9 +87,14 @@ class SignDocWrapper {
|
|
|
87
87
|
return this.aminoSignDoc.fee.amount;
|
|
88
88
|
}
|
|
89
89
|
get gas() {
|
|
90
|
-
var _a
|
|
90
|
+
var _a;
|
|
91
91
|
if (this.mode === "direct") {
|
|
92
|
-
|
|
92
|
+
if ((_a = this.protoSignDoc.authInfo.fee) === null || _a === void 0 ? void 0 : _a.gasLimit) {
|
|
93
|
+
return parseInt(this.protoSignDoc.authInfo.fee.gasLimit);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
93
98
|
}
|
|
94
99
|
return parseInt(this.aminoSignDoc.fee.gas);
|
|
95
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stargate/wrapper/index.ts"],"names":[],"mappings":";;;AAAA,wCAAiD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stargate/wrapper/index.ts"],"names":[],"mappings":";;;AAAA,wCAAiD;AAEjD,uEAAyE;AACzE,yCAAiE;AAEjE,MAAa,cAAc;IAOzB,YAA+B,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;QAC1D,IAAI,MAAM,IAAI,OAAO,EAAE;YACrB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;SACrB;aAAM;YACL,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;SACtB;QAED,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE;YACzB,yCAAyC;YACzC,gEAAgE;YAChE,yHAAyH;YACzH,IAAI,CAAC,cAAc,GAAG,0CAAiC,CACrD,IAAI,CAAC,YAAY,CAClB,CAAC;SACH;aAAM;YACL,oDAAoD;YACpD,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;SAC7B;IACH,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,OAAmB;QACzC,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,OAAgB;QACvC,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,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
@@ -10,23 +10,23 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"clean": "rm -rf node_modules; rm -rf build",
|
|
13
|
-
"build": "
|
|
14
|
-
"
|
|
15
|
-
"dev": "yarn build:proto && tsc -w",
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"dev": "tsc -w",
|
|
16
15
|
"test": "jest --passWithNoTests",
|
|
17
16
|
"lint-test": "eslint \"src/**/*\" && prettier --check \"src/**/*\"",
|
|
18
17
|
"lint-fix": "eslint --fix \"src/**/*\" && prettier --write \"src/**/*\""
|
|
19
18
|
},
|
|
20
19
|
"dependencies": {
|
|
21
20
|
"@cosmjs/launchpad": "^0.24.0-alpha.25",
|
|
22
|
-
"@keplr-wallet/crypto": "0.10.
|
|
23
|
-
"@keplr-wallet/types": "0.10.
|
|
24
|
-
"@keplr-wallet/
|
|
21
|
+
"@keplr-wallet/crypto": "0.10.1",
|
|
22
|
+
"@keplr-wallet/proto-types": "0.10.1",
|
|
23
|
+
"@keplr-wallet/types": "0.10.1",
|
|
24
|
+
"@keplr-wallet/unit": "0.10.1",
|
|
25
25
|
"axios": "^0.21.4",
|
|
26
26
|
"bech32": "^1.1.4",
|
|
27
27
|
"buffer": "^6.0.3",
|
|
28
28
|
"long": "^4.0.0",
|
|
29
|
-
"protobufjs": "^6.
|
|
29
|
+
"protobufjs": "^6.11.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "fe8b77605d5158bdb50ec8233dd698ad6e2e4f57"
|
|
32
32
|
}
|
|
@@ -1,63 +1,71 @@
|
|
|
1
|
-
import { google } from "../proto";
|
|
2
1
|
import * as $protobuf from "protobufjs";
|
|
3
|
-
|
|
4
|
-
import {
|
|
2
|
+
import { Any } from "@keplr-wallet/proto-types/google/protobuf/any";
|
|
3
|
+
import { MsgSend } from "@keplr-wallet/proto-types/cosmos/bank/v1beta1/tx";
|
|
4
|
+
import {
|
|
5
|
+
MsgDelegate,
|
|
6
|
+
MsgUndelegate,
|
|
7
|
+
MsgBeginRedelegate,
|
|
8
|
+
} from "@keplr-wallet/proto-types/cosmos/staking/v1beta1/tx";
|
|
9
|
+
import { MsgExecuteContract } from "@keplr-wallet/proto-types/cosmwasm/wasm/v1/tx";
|
|
5
10
|
import { UnknownMessage } from "./unknown";
|
|
6
11
|
|
|
7
12
|
export * from "./unknown";
|
|
8
13
|
|
|
14
|
+
export type AnyWithUnpacked =
|
|
15
|
+
| Any
|
|
16
|
+
| (Any & { unpacked: unknown; factory: ProtoFactory });
|
|
17
|
+
|
|
18
|
+
interface ProtoFactory {
|
|
19
|
+
encode: (message: any, writer?: $protobuf.Writer) => $protobuf.Writer;
|
|
20
|
+
decode: (r: $protobuf.Reader | Uint8Array, l?: number) => any;
|
|
21
|
+
fromJSON: (object: any) => any;
|
|
22
|
+
toJSON: (message: any) => unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
export class ProtoCodec {
|
|
10
|
-
protected typeUrlMap: Map<
|
|
11
|
-
string,
|
|
12
|
-
{
|
|
13
|
-
decode: (r: $protobuf.Reader | Uint8Array, l?: number) => any;
|
|
14
|
-
}
|
|
15
|
-
> = new Map();
|
|
26
|
+
protected typeUrlMap: Map<string, ProtoFactory> = new Map();
|
|
16
27
|
|
|
17
28
|
/**
|
|
18
29
|
* Unpack the any to the registered message.
|
|
19
30
|
* NOTE: If there is no matched message, it will not throw an error but return the `UnknownMessage` class.
|
|
20
|
-
* @param
|
|
31
|
+
* @param any
|
|
21
32
|
*/
|
|
22
|
-
unpackAny(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!this.typeUrlMap.has(any.type_url)) {
|
|
26
|
-
return new UnknownMessage(any.type_url, any.value);
|
|
33
|
+
unpackAny(any: Any): AnyWithUnpacked {
|
|
34
|
+
if (!this.typeUrlMap.has(any.typeUrl)) {
|
|
35
|
+
return new UnknownMessage(any.typeUrl, any.value);
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
30
|
-
|
|
39
|
+
const factory = this.typeUrlMap.get(any.typeUrl)!;
|
|
40
|
+
const unpacked = factory.decode(any.value);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
...any,
|
|
44
|
+
unpacked,
|
|
45
|
+
factory,
|
|
46
|
+
};
|
|
31
47
|
}
|
|
32
48
|
|
|
33
|
-
registerAny(
|
|
34
|
-
typeUrl: string,
|
|
35
|
-
message: {
|
|
36
|
-
decode: (r: $protobuf.Reader | Uint8Array, l?: number) => any;
|
|
37
|
-
}
|
|
38
|
-
): void {
|
|
49
|
+
registerAny(typeUrl: string, message: ProtoFactory): void {
|
|
39
50
|
this.typeUrlMap.set(typeUrl, message);
|
|
40
51
|
}
|
|
41
52
|
}
|
|
42
53
|
|
|
43
54
|
export const defaultProtoCodec = new ProtoCodec();
|
|
44
|
-
defaultProtoCodec.registerAny(
|
|
45
|
-
"/cosmos.bank.v1beta1.MsgSend",
|
|
46
|
-
cosmos.bank.v1beta1.MsgSend
|
|
47
|
-
);
|
|
55
|
+
defaultProtoCodec.registerAny("/cosmos.bank.v1beta1.MsgSend", MsgSend);
|
|
48
56
|
defaultProtoCodec.registerAny(
|
|
49
57
|
"/cosmos.staking.v1beta1.MsgDelegate",
|
|
50
|
-
|
|
58
|
+
MsgDelegate
|
|
51
59
|
);
|
|
52
60
|
defaultProtoCodec.registerAny(
|
|
53
61
|
"/cosmos.staking.v1beta1.MsgUndelegate",
|
|
54
|
-
|
|
62
|
+
MsgUndelegate
|
|
55
63
|
);
|
|
56
64
|
defaultProtoCodec.registerAny(
|
|
57
65
|
"/cosmos.staking.v1beta1.MsgBeginRedelegate",
|
|
58
|
-
|
|
66
|
+
MsgBeginRedelegate
|
|
59
67
|
);
|
|
60
68
|
defaultProtoCodec.registerAny(
|
|
61
69
|
"/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
62
|
-
|
|
70
|
+
MsgExecuteContract
|
|
63
71
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import { ProtoSignDocDecoder } from "./index";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { MsgSend } from "@keplr-wallet/proto-types/cosmos/bank/v1beta1/tx";
|
|
5
5
|
|
|
6
6
|
describe("Test decode sign doc", () => {
|
|
7
7
|
it("should decode properly", function () {
|
|
@@ -79,7 +79,10 @@ d701a0c0a057374616b65120331303012580a500a460a1f2f636f736d6f732e63727970746f2e736
|
|
|
79
79
|
|
|
80
80
|
assert.strictEqual(signDoc.txMsgs.length, 1);
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
if (!("unpacked" in signDoc.txMsgs[0])) {
|
|
83
|
+
throw new Error("Msgs not parsed properly");
|
|
84
|
+
}
|
|
85
|
+
const msg = signDoc.txMsgs[0].unpacked as MsgSend;
|
|
83
86
|
assert.strictEqual(
|
|
84
87
|
msg.fromAddress,
|
|
85
88
|
"cosmos1xesvkr6d0j96j5zdcw5fmqxavjvuvqx2ygy7mp"
|
|
@@ -1,30 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
SignDoc,
|
|
3
|
+
TxBody,
|
|
4
|
+
AuthInfo,
|
|
5
|
+
} from "@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx";
|
|
6
|
+
import {
|
|
7
|
+
AnyWithUnpacked,
|
|
8
|
+
defaultProtoCodec,
|
|
9
|
+
ProtoCodec,
|
|
10
|
+
UnknownMessage,
|
|
11
|
+
} from "../codec";
|
|
4
12
|
|
|
5
13
|
export class ProtoSignDocDecoder {
|
|
6
14
|
public static decode(bytes: Uint8Array): ProtoSignDocDecoder {
|
|
7
|
-
return new ProtoSignDocDecoder(
|
|
15
|
+
return new ProtoSignDocDecoder(SignDoc.decode(bytes));
|
|
8
16
|
}
|
|
9
17
|
|
|
10
|
-
protected _txBody?:
|
|
11
|
-
protected _authInfo?:
|
|
18
|
+
protected _txBody?: TxBody;
|
|
19
|
+
protected _authInfo?: AuthInfo;
|
|
12
20
|
|
|
13
21
|
constructor(
|
|
14
22
|
public readonly signDoc: SignDoc,
|
|
15
23
|
protected readonly protoCodec: ProtoCodec = defaultProtoCodec
|
|
16
24
|
) {}
|
|
17
25
|
|
|
18
|
-
get txBody():
|
|
26
|
+
get txBody(): TxBody {
|
|
19
27
|
if (!this._txBody) {
|
|
20
|
-
this._txBody =
|
|
28
|
+
this._txBody = TxBody.decode(this.signDoc.bodyBytes);
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
return this._txBody;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
|
-
get txMsgs():
|
|
27
|
-
const msgs:
|
|
34
|
+
get txMsgs(): AnyWithUnpacked[] {
|
|
35
|
+
const msgs: AnyWithUnpacked[] = [];
|
|
28
36
|
for (const msg of this.txBody.messages) {
|
|
29
37
|
msgs.push(this.protoCodec.unpackAny(msg));
|
|
30
38
|
}
|
|
@@ -32,11 +40,9 @@ export class ProtoSignDocDecoder {
|
|
|
32
40
|
return msgs;
|
|
33
41
|
}
|
|
34
42
|
|
|
35
|
-
get authInfo():
|
|
43
|
+
get authInfo(): AuthInfo {
|
|
36
44
|
if (!this._authInfo) {
|
|
37
|
-
this._authInfo =
|
|
38
|
-
this.signDoc.authInfoBytes
|
|
39
|
-
);
|
|
45
|
+
this._authInfo = AuthInfo.decode(this.signDoc.authInfoBytes);
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
return this._authInfo;
|
|
@@ -51,23 +57,28 @@ export class ProtoSignDocDecoder {
|
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
toBytes(): Uint8Array {
|
|
54
|
-
return
|
|
60
|
+
return SignDoc.encode(this.signDoc).finish();
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
toJSON(): any {
|
|
58
64
|
return {
|
|
59
65
|
txBody: {
|
|
60
|
-
...this.txBody
|
|
66
|
+
...(TxBody.toJSON(this.txBody) as any),
|
|
61
67
|
...{
|
|
62
68
|
messages: this.txMsgs.map((msg) => {
|
|
63
|
-
if (msg
|
|
64
|
-
|
|
69
|
+
if (msg) {
|
|
70
|
+
if (msg instanceof UnknownMessage) {
|
|
71
|
+
return msg.toJSON();
|
|
72
|
+
}
|
|
73
|
+
if ("factory" in msg) {
|
|
74
|
+
return msg.factory.toJSON(msg.unpacked);
|
|
75
|
+
}
|
|
65
76
|
}
|
|
66
77
|
return msg;
|
|
67
78
|
}),
|
|
68
79
|
},
|
|
69
80
|
},
|
|
70
|
-
authInfo: this.authInfo
|
|
81
|
+
authInfo: AuthInfo.toJSON(this.authInfo),
|
|
71
82
|
chainId: this.chainId,
|
|
72
83
|
accountNumber: this.accountNumber,
|
|
73
84
|
};
|
package/src/stargate/index.ts
CHANGED