@airgap/cosmos 0.13.11-beta.14 → 0.13.11-beta.15
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/LICENSE.md +7 -7
- package/package.json +2 -3
- package/v1/data/CosmosAddress.d.ts +7 -0
- package/v1/data/CosmosAddress.js +29 -0
- package/v1/data/CosmosAddress.js.map +1 -0
- package/v1/data/CosmosCoin.d.ts +19 -0
- package/v1/data/CosmosCoin.js +55 -0
- package/v1/data/CosmosCoin.js.map +1 -0
- package/v1/data/CosmosFee.d.ts +15 -0
- package/v1/data/CosmosFee.js +31 -0
- package/v1/data/CosmosFee.js.map +1 -0
- package/v1/data/transaction/CosmosTransaction.d.ts +36 -0
- package/v1/data/transaction/CosmosTransaction.js +109 -0
- package/v1/data/transaction/CosmosTransaction.js.map +1 -0
- package/v1/data/transaction/message/CosmosDelegateMessage.d.ts +19 -0
- package/v1/data/transaction/message/CosmosDelegateMessage.js +70 -0
- package/v1/data/transaction/message/CosmosDelegateMessage.js.map +1 -0
- package/v1/data/transaction/message/CosmosMessage.d.ts +38 -0
- package/v1/data/transaction/message/CosmosMessage.js +47 -0
- package/v1/data/transaction/message/CosmosMessage.js.map +1 -0
- package/v1/data/transaction/message/CosmosSendMessage.d.ts +19 -0
- package/v1/data/transaction/message/CosmosSendMessage.js +83 -0
- package/v1/data/transaction/message/CosmosSendMessage.js.map +1 -0
- package/v1/data/transaction/message/CosmosWithdrawDelegationRewardMessage.d.ts +23 -0
- package/v1/data/transaction/message/CosmosWithdrawDelegationRewardMessage.js +61 -0
- package/v1/data/transaction/message/CosmosWithdrawDelegationRewardMessage.js.map +1 -0
- package/v1/index.d.ts +6 -2
- package/v1/index.js.map +1 -1
- package/v1/module/CosmosModule.js +1 -1
- package/v1/module/CosmosModule.js.map +1 -1
- package/v1/node/CosmosNodeClient.d.ts +28 -0
- package/v1/node/CosmosNodeClient.js +381 -0
- package/v1/node/CosmosNodeClient.js.map +1 -0
- package/v1/protocol/CosmosCryptoClient.d.ts +8 -0
- package/v1/protocol/CosmosCryptoClient.js +90 -0
- package/v1/protocol/CosmosCryptoClient.js.map +1 -0
- package/v1/protocol/CosmosProtocol.d.ts +47 -10
- package/v1/protocol/CosmosProtocol.js +531 -41
- package/v1/protocol/CosmosProtocol.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +7 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +37 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-cosmos.d.ts +4 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-cosmos.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-cosmos.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-cosmos.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-cosmos.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-cosmos.js.map +1 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-cosmos.json +100 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-cosmos.json +19 -0
- package/v1/serializer/v3/serializer-companion.js +7 -7
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validators.d.ts +7 -0
- package/v1/serializer/v3/validators/transaction-validators.js +88 -0
- package/v1/serializer/v3/validators/transaction-validators.js.map +1 -0
- package/v1/types/crypto.d.ts +2 -0
- package/v1/types/crypto.js +3 -0
- package/v1/types/crypto.js.map +1 -0
- package/v1/types/protocol.d.ts +8 -0
- package/v1/types/protocol.js +3 -0
- package/v1/types/protocol.js.map +1 -0
- package/v1/types/rpc.d.ts +286 -0
- package/v1/types/rpc.js +3 -0
- package/v1/types/rpc.js.map +1 -0
- package/v1/types/transaction.d.ts +44 -0
- package/v1/types/transaction.js +10 -0
- package/v1/types/transaction.js.map +1 -0
- package/v1/utils/key.d.ts +3 -0
- package/v1/utils/key.js +20 -0
- package/v1/utils/key.js.map +1 -0
- package/v1/utils/signature.d.ts +2 -0
- package/v1/utils/signature.js +13 -0
- package/v1/utils/signature.js.map +1 -0
- package/v1/utils/transaction.d.ts +1 -0
- package/v1/utils/transaction.js +8 -0
- package/v1/utils/transaction.js.map +1 -0
package/LICENSE.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2019 Papers
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
Copyright 2019 Papers GmbH
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airgap/cosmos",
|
|
3
|
-
"version": "0.13.11-beta.
|
|
3
|
+
"version": "0.13.11-beta.15",
|
|
4
4
|
"description": "The @airgap/cosmos is a Cosmos implementation of the ICoinProtocol interface from @airgap/coinlib-core.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"airgap",
|
|
@@ -28,10 +28,9 @@
|
|
|
28
28
|
"test-ci": "nyc --reporter=lcov npm test",
|
|
29
29
|
"browserify": "browserify ./dist/index.js -s airgapCoinLibCosmos > ./dist/airgap-coinlib-cosmos.min.js"
|
|
30
30
|
},
|
|
31
|
-
"author": "Papers
|
|
31
|
+
"author": "Papers GmbH <contact@papers.ch> (https://papers.ch)",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@airgap/coinlib-core": "*",
|
|
34
|
-
"@airgap/cosmos-core": "*",
|
|
35
34
|
"@airgap/crypto": "*",
|
|
36
35
|
"@airgap/module-kit": "*",
|
|
37
36
|
"@airgap/serializer": "*"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CosmosAddress = void 0;
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
var BECH32 = require("@airgap/coinlib-core/dependencies/src/bech32-1.1.3/index");
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
var RIPEMD160 = require("@airgap/coinlib-core/dependencies/src/ripemd160-2.0.2/index");
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
var sha = require("@airgap/coinlib-core/dependencies/src/sha.js-2.4.11/index");
|
|
10
|
+
var key_1 = require("../utils/key");
|
|
11
|
+
var ADDRESS_PREFIX = 'cosmos';
|
|
12
|
+
var CosmosAddress = /** @class */ (function () {
|
|
13
|
+
function CosmosAddress(value) {
|
|
14
|
+
this.value = value;
|
|
15
|
+
}
|
|
16
|
+
CosmosAddress.from = function (publicKey) {
|
|
17
|
+
var hexPublicKey = (0, key_1.convertPublicKey)(publicKey, 'hex');
|
|
18
|
+
var sha256Hash = sha('sha256').update(Buffer.from(hexPublicKey.value, 'hex')).digest();
|
|
19
|
+
var hash = new RIPEMD160().update(Buffer.from(sha256Hash)).digest();
|
|
20
|
+
var address = BECH32.encode(ADDRESS_PREFIX, BECH32.toWords(hash));
|
|
21
|
+
return new CosmosAddress(address);
|
|
22
|
+
};
|
|
23
|
+
CosmosAddress.prototype.asString = function () {
|
|
24
|
+
return this.value;
|
|
25
|
+
};
|
|
26
|
+
return CosmosAddress;
|
|
27
|
+
}());
|
|
28
|
+
exports.CosmosAddress = CosmosAddress;
|
|
29
|
+
//# sourceMappingURL=CosmosAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CosmosAddress.js","sourceRoot":"","sources":["../../../src/v1/data/CosmosAddress.ts"],"names":[],"mappings":";;;AAAA,aAAa;AACb,iFAAmF;AACnF,aAAa;AACb,uFAAyF;AACzF,aAAa;AACb,+EAAiF;AAGjF,oCAA+C;AAE/C,IAAM,cAAc,GAAW,QAAQ,CAAA;AAEvC;IACE,uBAAqC,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAExC,kBAAI,GAAlB,UAAmB,SAAoB;QACrC,IAAM,YAAY,GAAc,IAAA,sBAAgB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QAElE,IAAM,UAAU,GAAW,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAA;QAChG,IAAM,IAAI,GAAG,IAAI,SAAS,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAA;QACrE,IAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;QAEnE,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC;IAEM,gCAAQ,GAAf;QACE,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IACH,oBAAC;AAAD,CAAC,AAhBD,IAgBC;AAhBY,sCAAa"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import BigNumber from '@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber';
|
|
2
|
+
import { JSONConvertible } from '@airgap/coinlib-core/interfaces/JSONConvertible';
|
|
3
|
+
import { RPCConvertible } from '@airgap/coinlib-core/interfaces/RPCConvertible';
|
|
4
|
+
export interface CosmosCoinJSON {
|
|
5
|
+
denom: string;
|
|
6
|
+
amount: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CosmosCoin implements JSONConvertible, RPCConvertible {
|
|
9
|
+
private static readonly supportedDenominations;
|
|
10
|
+
readonly denom: string;
|
|
11
|
+
readonly amount: string;
|
|
12
|
+
constructor(denom: string, amount: string);
|
|
13
|
+
toJSON(): CosmosCoinJSON;
|
|
14
|
+
static fromJSON(json: CosmosCoinJSON): CosmosCoin;
|
|
15
|
+
static fromCoins(json: CosmosCoinJSON[]): CosmosCoin[];
|
|
16
|
+
static sum(coins: CosmosCoin[]): BigNumber;
|
|
17
|
+
toRPCBody(): any;
|
|
18
|
+
static fromRPCBody(json: any): CosmosCoin;
|
|
19
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CosmosCoin = void 0;
|
|
7
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
8
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
9
|
+
var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
|
|
10
|
+
var CosmosCoin = /** @class */ (function () {
|
|
11
|
+
function CosmosCoin(denom, amount) {
|
|
12
|
+
this.denom = denom;
|
|
13
|
+
this.amount = amount;
|
|
14
|
+
}
|
|
15
|
+
CosmosCoin.prototype.toJSON = function () {
|
|
16
|
+
return {
|
|
17
|
+
amount: this.amount,
|
|
18
|
+
denom: this.denom
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
CosmosCoin.fromJSON = function (json) {
|
|
22
|
+
if (!CosmosCoin.supportedDenominations.includes(json.denom)) {
|
|
23
|
+
throw new errors_1.UnsupportedError(coinlib_error_1.Domain.COSMOS, 'Unsupported cosmos denomination');
|
|
24
|
+
}
|
|
25
|
+
return new CosmosCoin(json.denom, json.amount);
|
|
26
|
+
};
|
|
27
|
+
CosmosCoin.fromCoins = function (json) {
|
|
28
|
+
return json
|
|
29
|
+
.map(function (coinJSON) {
|
|
30
|
+
try {
|
|
31
|
+
return CosmosCoin.fromJSON(coinJSON);
|
|
32
|
+
}
|
|
33
|
+
catch (_a) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
.filter(function (value) { return value !== undefined; });
|
|
38
|
+
};
|
|
39
|
+
CosmosCoin.sum = function (coins) {
|
|
40
|
+
return coins.reduce(function (current, next) { return current.plus(new bignumber_1.default(next.amount)); }, new bignumber_1.default(0));
|
|
41
|
+
};
|
|
42
|
+
CosmosCoin.prototype.toRPCBody = function () {
|
|
43
|
+
return {
|
|
44
|
+
amount: this.amount,
|
|
45
|
+
denom: this.denom
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
CosmosCoin.fromRPCBody = function (json) {
|
|
49
|
+
return new CosmosCoin(json.denom, json.amount);
|
|
50
|
+
};
|
|
51
|
+
CosmosCoin.supportedDenominations = ['uatom'];
|
|
52
|
+
return CosmosCoin;
|
|
53
|
+
}());
|
|
54
|
+
exports.CosmosCoin = CosmosCoin;
|
|
55
|
+
//# sourceMappingURL=CosmosCoin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CosmosCoin.js","sourceRoot":"","sources":["../../../src/v1/data/CosmosCoin.ts"],"names":[],"mappings":";;;;;;AAAA,iHAA0F;AAC1F,sDAA8D;AAC9D,2EAAkE;AASlE;IAKE,oBAAY,KAAa,EAAE,MAAc;QACvC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEM,2BAAM,GAAb;QACE,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAA;IACH,CAAC;IAEa,mBAAQ,GAAtB,UAAuB,IAAoB;QACzC,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YAC3D,MAAM,IAAI,yBAAgB,CAAC,sBAAM,CAAC,MAAM,EAAE,iCAAiC,CAAC,CAAA;SAC7E;QAED,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAChD,CAAC;IAEa,oBAAS,GAAvB,UAAwB,IAAsB;QAC5C,OAAO,IAAI;aACR,GAAG,CAAC,UAAC,QAAQ;YACZ,IAAI;gBACF,OAAO,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;aACrC;YAAC,WAAM;gBACN,OAAO,SAAS,CAAA;aACjB;QACH,CAAC,CAAC;aACD,MAAM,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,KAAK,SAAS,EAAnB,CAAmB,CAAiB,CAAA;IAC3D,CAAC;IAEa,cAAG,GAAjB,UAAkB,KAAmB;QACnC,OAAO,KAAK,CAAC,MAAM,CAAC,UAAC,OAAO,EAAE,IAAI,IAAK,OAAA,OAAO,CAAC,IAAI,CAAC,IAAI,mBAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAxC,CAAwC,EAAE,IAAI,mBAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IACpG,CAAC;IAEM,8BAAS,GAAhB;QACE,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAA;IACH,CAAC;IAEa,sBAAW,GAAzB,UAA0B,IAAS;QACjC,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAChD,CAAC;IAjDuB,iCAAsB,GAAG,CAAC,OAAO,CAAC,CAAA;IAkD5D,iBAAC;CAAA,AAnDD,IAmDC;AAnDY,gCAAU"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { JSONConvertible } from '@airgap/coinlib-core/interfaces/JSONConvertible';
|
|
2
|
+
import { RPCConvertible } from '@airgap/coinlib-core/interfaces/RPCConvertible';
|
|
3
|
+
import { CosmosCoin } from './CosmosCoin';
|
|
4
|
+
export declare class CosmosFee implements JSONConvertible, RPCConvertible {
|
|
5
|
+
readonly amount: CosmosCoin[];
|
|
6
|
+
readonly gas: string;
|
|
7
|
+
constructor(amount: CosmosCoin[], gas: string);
|
|
8
|
+
toJSON(): {
|
|
9
|
+
amount: import("./CosmosCoin").CosmosCoinJSON[];
|
|
10
|
+
gas: string;
|
|
11
|
+
};
|
|
12
|
+
static fromJSON(json: any): CosmosFee;
|
|
13
|
+
toRPCBody(): any;
|
|
14
|
+
static fromRPCBody(json: any): CosmosFee;
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CosmosFee = void 0;
|
|
4
|
+
var CosmosCoin_1 = require("./CosmosCoin");
|
|
5
|
+
var CosmosFee = /** @class */ (function () {
|
|
6
|
+
function CosmosFee(amount, gas) {
|
|
7
|
+
this.amount = amount;
|
|
8
|
+
this.gas = gas;
|
|
9
|
+
}
|
|
10
|
+
CosmosFee.prototype.toJSON = function () {
|
|
11
|
+
return {
|
|
12
|
+
amount: this.amount.map(function (value) { return value.toJSON(); }),
|
|
13
|
+
gas: this.gas
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
CosmosFee.fromJSON = function (json) {
|
|
17
|
+
return new CosmosFee(json.amount.map(function (value) { return CosmosCoin_1.CosmosCoin.fromJSON(value); }), json.gas);
|
|
18
|
+
};
|
|
19
|
+
CosmosFee.prototype.toRPCBody = function () {
|
|
20
|
+
return {
|
|
21
|
+
amount: this.amount.map(function (value) { return value.toRPCBody(); }),
|
|
22
|
+
gas: this.gas
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
CosmosFee.fromRPCBody = function (json) {
|
|
26
|
+
return new CosmosFee(json.amount.map(function (value) { return CosmosCoin_1.CosmosCoin.fromRPCBody(value); }), json.gas);
|
|
27
|
+
};
|
|
28
|
+
return CosmosFee;
|
|
29
|
+
}());
|
|
30
|
+
exports.CosmosFee = CosmosFee;
|
|
31
|
+
//# sourceMappingURL=CosmosFee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CosmosFee.js","sourceRoot":"","sources":["../../../src/v1/data/CosmosFee.ts"],"names":[],"mappings":";;;AAGA,2CAAyC;AAEzC;IAIE,mBAAY,MAAoB,EAAE,GAAW;QAC3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAEM,0BAAM,GAAb;QACE,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,MAAM,EAAE,EAAd,CAAc,CAAC;YAClD,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAA;IACH,CAAC;IAEa,kBAAQ,GAAtB,UAAuB,IAAS;QAC9B,OAAO,IAAI,SAAS,CAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAC,KAAU,IAAK,OAAA,uBAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,EAA1B,CAA0B,CAAC,EAC3D,IAAI,CAAC,GAAG,CACT,CAAA;IACH,CAAC;IAEM,6BAAS,GAAhB;QACE,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,SAAS,EAAE,EAAjB,CAAiB,CAAC;YACrD,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAA;IACH,CAAC;IAEa,qBAAW,GAAzB,UAA0B,IAAS;QACjC,OAAO,IAAI,SAAS,CAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAC,KAAU,IAAK,OAAA,uBAAU,CAAC,WAAW,CAAC,KAAK,CAAC,EAA7B,CAA6B,CAAC,EAC9D,IAAI,CAAC,GAAG,CACT,CAAA;IACH,CAAC;IACH,gBAAC;AAAD,CAAC,AApCD,IAoCC;AApCY,8BAAS"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EncodeObject } from '@airgap/coinlib-core/dependencies/src/cosmjs';
|
|
2
|
+
import { JSONConvertible } from '@airgap/coinlib-core/interfaces/JSONConvertible';
|
|
3
|
+
import { RPCConvertible } from '@airgap/coinlib-core/interfaces/RPCConvertible';
|
|
4
|
+
import { AirGapTransaction } from '@airgap/module-kit';
|
|
5
|
+
import { CosmosProtocolNetwork, CosmosUnits } from '../../types/protocol';
|
|
6
|
+
import { CosmosUnsignedTransaction } from '../../types/transaction';
|
|
7
|
+
import { CosmosFee } from '../CosmosFee';
|
|
8
|
+
import { CosmosMessage } from './message/CosmosMessage';
|
|
9
|
+
export interface Encodable {
|
|
10
|
+
toEncodeObject(): EncodeObject;
|
|
11
|
+
}
|
|
12
|
+
export declare class CosmosTransaction implements JSONConvertible, RPCConvertible, Encodable {
|
|
13
|
+
readonly messages: CosmosMessage[];
|
|
14
|
+
readonly fee: CosmosFee;
|
|
15
|
+
readonly memo: string;
|
|
16
|
+
readonly chainID: string;
|
|
17
|
+
readonly accountNumber: string;
|
|
18
|
+
readonly sequence: string;
|
|
19
|
+
constructor(messages: CosmosMessage[], fee: CosmosFee, memo: string, chainID: string, accountNumber: string, sequence: string);
|
|
20
|
+
toJSON(): {
|
|
21
|
+
accountNumber: string;
|
|
22
|
+
chainID: string;
|
|
23
|
+
fee: {
|
|
24
|
+
amount: import("../CosmosCoin").CosmosCoinJSON[];
|
|
25
|
+
gas: string;
|
|
26
|
+
};
|
|
27
|
+
memo: string;
|
|
28
|
+
messages: import("./message/CosmosMessage").CosmosMessageJSON[];
|
|
29
|
+
sequence: string;
|
|
30
|
+
};
|
|
31
|
+
toRPCBody(): any;
|
|
32
|
+
toEncodeObject(): EncodeObject;
|
|
33
|
+
toAirGapTransactions(network: CosmosProtocolNetwork): AirGapTransaction<CosmosUnits>[];
|
|
34
|
+
static fromJSON(json: CosmosUnsignedTransaction): CosmosTransaction;
|
|
35
|
+
static fromRPCBody(json: any): CosmosTransaction;
|
|
36
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CosmosTransaction = void 0;
|
|
7
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
8
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
9
|
+
var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
|
|
10
|
+
var CosmosFee_1 = require("../CosmosFee");
|
|
11
|
+
var CosmosDelegateMessage_1 = require("./message/CosmosDelegateMessage");
|
|
12
|
+
var CosmosMessage_1 = require("./message/CosmosMessage");
|
|
13
|
+
var CosmosSendMessage_1 = require("./message/CosmosSendMessage");
|
|
14
|
+
var CosmosWithdrawDelegationRewardMessage_1 = require("./message/CosmosWithdrawDelegationRewardMessage");
|
|
15
|
+
var CosmosTransaction = /** @class */ (function () {
|
|
16
|
+
function CosmosTransaction(messages, fee, memo, chainID, accountNumber, sequence) {
|
|
17
|
+
this.messages = messages;
|
|
18
|
+
this.fee = fee;
|
|
19
|
+
this.memo = memo;
|
|
20
|
+
this.chainID = chainID;
|
|
21
|
+
this.accountNumber = accountNumber;
|
|
22
|
+
this.sequence = sequence;
|
|
23
|
+
}
|
|
24
|
+
CosmosTransaction.prototype.toJSON = function () {
|
|
25
|
+
return {
|
|
26
|
+
accountNumber: this.accountNumber,
|
|
27
|
+
chainID: this.chainID,
|
|
28
|
+
fee: this.fee.toJSON(),
|
|
29
|
+
memo: this.memo,
|
|
30
|
+
messages: this.messages.map(function (value) { return value.toJSON(); }),
|
|
31
|
+
sequence: this.sequence
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
CosmosTransaction.prototype.toRPCBody = function () {
|
|
35
|
+
return {
|
|
36
|
+
account_number: this.accountNumber,
|
|
37
|
+
chain_id: this.chainID,
|
|
38
|
+
fee: this.fee.toRPCBody(),
|
|
39
|
+
memo: this.memo,
|
|
40
|
+
msgs: this.messages.map(function (value) { return value.toRPCBody(); }),
|
|
41
|
+
sequence: this.sequence
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
CosmosTransaction.prototype.toEncodeObject = function () {
|
|
45
|
+
return {
|
|
46
|
+
typeUrl: '/cosmos.tx.v1beta1.TxBody',
|
|
47
|
+
value: {
|
|
48
|
+
messages: this.messages.map(function (msg) { return msg.toEncodeObject(); }),
|
|
49
|
+
memo: this.memo
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
CosmosTransaction.prototype.toAirGapTransactions = function (network) {
|
|
54
|
+
var _this = this;
|
|
55
|
+
var fee = this.fee.amount.map(function (value) { return new bignumber_1.default(value.amount); }).reduce(function (prev, next) { return prev.plus(next); });
|
|
56
|
+
return this.messages
|
|
57
|
+
.map(function (message) { return message.toAirGapTransaction(network, fee.toString(10)); })
|
|
58
|
+
.map(function (tx) {
|
|
59
|
+
if (!tx.json) {
|
|
60
|
+
tx.json = {};
|
|
61
|
+
}
|
|
62
|
+
tx.json.accountNumber = _this.accountNumber;
|
|
63
|
+
tx.json.chainID = _this.chainID;
|
|
64
|
+
tx.json.memo = _this.memo;
|
|
65
|
+
tx.json.sequence = _this.sequence;
|
|
66
|
+
tx.arbitraryData = _this.memo;
|
|
67
|
+
return tx;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
CosmosTransaction.fromJSON = function (json) {
|
|
71
|
+
json = JSON.parse(JSON.stringify(json));
|
|
72
|
+
var messages = json.messages.map(function (value) {
|
|
73
|
+
var type = value.type;
|
|
74
|
+
switch (type) {
|
|
75
|
+
case CosmosMessage_1.CosmosMessageType.Send.index:
|
|
76
|
+
return CosmosSendMessage_1.CosmosSendMessage.fromJSON(value);
|
|
77
|
+
case CosmosMessage_1.CosmosMessageType.Delegate.index:
|
|
78
|
+
case CosmosMessage_1.CosmosMessageType.Undelegate.index:
|
|
79
|
+
return CosmosDelegateMessage_1.CosmosDelegateMessage.fromJSON(value);
|
|
80
|
+
case CosmosMessage_1.CosmosMessageType.WithdrawDelegationReward.index:
|
|
81
|
+
return CosmosWithdrawDelegationRewardMessage_1.CosmosWithdrawDelegationRewardMessage.fromJSON(value);
|
|
82
|
+
default:
|
|
83
|
+
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.COSMOS, 'Unknown message');
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return new CosmosTransaction(messages, CosmosFee_1.CosmosFee.fromJSON(json.fee), json.memo, json.chainID, json.accountNumber, json.sequence);
|
|
87
|
+
};
|
|
88
|
+
CosmosTransaction.fromRPCBody = function (json) {
|
|
89
|
+
json = JSON.parse(JSON.stringify(json));
|
|
90
|
+
var messages = json.msgs.map(function (value) {
|
|
91
|
+
var type = value.type;
|
|
92
|
+
switch (type) {
|
|
93
|
+
case CosmosMessage_1.CosmosMessageType.Send.value:
|
|
94
|
+
return CosmosSendMessage_1.CosmosSendMessage.fromRPCBody(value);
|
|
95
|
+
case CosmosMessage_1.CosmosMessageType.Delegate.value:
|
|
96
|
+
case CosmosMessage_1.CosmosMessageType.Undelegate.value:
|
|
97
|
+
return CosmosDelegateMessage_1.CosmosDelegateMessage.fromRPCBody(value);
|
|
98
|
+
case CosmosMessage_1.CosmosMessageType.WithdrawDelegationReward.value:
|
|
99
|
+
return CosmosWithdrawDelegationRewardMessage_1.CosmosWithdrawDelegationRewardMessage.fromRPCBody(value);
|
|
100
|
+
default:
|
|
101
|
+
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.COSMOS, 'Unknown message');
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return new CosmosTransaction(messages, CosmosFee_1.CosmosFee.fromRPCBody(json.fee), json.memo, json.chain_id, json.account_number, json.sequence);
|
|
105
|
+
};
|
|
106
|
+
return CosmosTransaction;
|
|
107
|
+
}());
|
|
108
|
+
exports.CosmosTransaction = CosmosTransaction;
|
|
109
|
+
//# sourceMappingURL=CosmosTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CosmosTransaction.js","sourceRoot":"","sources":["../../../../src/v1/data/transaction/CosmosTransaction.ts"],"names":[],"mappings":";;;;;;AAAA,iHAA0F;AAE1F,sDAA+D;AAC/D,2EAAkE;AAOlE,0CAAwC;AAExC,yEAAuE;AACvE,yDAAkG;AAClG,iEAA+D;AAC/D,yGAAuG;AAMvG;IAQE,2BAAY,QAAyB,EAAE,GAAc,EAAE,IAAY,EAAE,OAAe,EAAE,aAAqB,EAAE,QAAgB;QAC3H,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAEM,kCAAM,GAAb;QACE,OAAO;YACL,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;YACtB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,MAAM,EAAE,EAAd,CAAc,CAAC;YACtD,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAA;IACH,CAAC;IAEM,qCAAS,GAAhB;QACE,OAAO;YACL,cAAc,EAAE,IAAI,CAAC,aAAa;YAClC,QAAQ,EAAE,IAAI,CAAC,OAAO;YACtB,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;YACzB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,QAAQ,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AAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;QACvC,IAAM,QAAQ,GAAoB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAC,KAAU;YACzD,IAAM,IAAI,GAAW,KAAK,CAAC,IAAI,CAAA;YAC/B,QAAQ,IAAI,EAAE;gBACZ,KAAK,iCAAiB,CAAC,IAAI,CAAC,KAAK;oBAC/B,OAAO,qCAAiB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;gBAC7C,KAAK,iCAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC;gBACtC,KAAK,iCAAiB,CAAC,UAAU,CAAC,KAAK;oBACrC,OAAO,6CAAqB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;gBACjD,KAAK,iCAAiB,CAAC,wBAAwB,CAAC,KAAK;oBACnD,OAAO,6EAAqC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;gBACjE;oBACE,MAAM,IAAI,0BAAiB,CAAC,sBAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA;aAChE;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,iBAAiB,CAAC,QAAQ,EAAE,qBAAS,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IACvI,CAAC;IACH,wBAAC;AAAD,CAAC,AA5GD,IA4GC;AA5GY,8CAAiB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EncodeObject } from '@airgap/coinlib-core/dependencies/src/cosmjs';
|
|
2
|
+
import { AirGapTransaction } from '@airgap/module-kit';
|
|
3
|
+
import { CosmosProtocolNetwork, CosmosUnits } from '../../../types/protocol';
|
|
4
|
+
import { CosmosCoin } from '../../CosmosCoin';
|
|
5
|
+
import { CosmosMessage, CosmosMessageJSON, CosmosMessageType } from './CosmosMessage';
|
|
6
|
+
export declare class CosmosDelegateMessage implements CosmosMessage {
|
|
7
|
+
readonly delegatorAddress: string;
|
|
8
|
+
readonly validatorAddress: string;
|
|
9
|
+
readonly amount: CosmosCoin;
|
|
10
|
+
readonly type: CosmosMessageType;
|
|
11
|
+
constructor(delegatorAddress: string, validatorAddress: string, amount: CosmosCoin, undelegate?: boolean);
|
|
12
|
+
toEncodeObject(): EncodeObject;
|
|
13
|
+
static fromEncodeObject(encodeObject: EncodeObject): CosmosDelegateMessage;
|
|
14
|
+
toJSON(): CosmosMessageJSON;
|
|
15
|
+
static fromJSON(json: CosmosMessageJSON): CosmosDelegateMessage;
|
|
16
|
+
toRPCBody(): any;
|
|
17
|
+
toAirGapTransaction(network: CosmosProtocolNetwork, fee: string): AirGapTransaction<CosmosUnits>;
|
|
18
|
+
static fromRPCBody(json: any): CosmosDelegateMessage;
|
|
19
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CosmosDelegateMessage = void 0;
|
|
4
|
+
var IAirGapTransaction_1 = require("@airgap/coinlib-core/interfaces/IAirGapTransaction");
|
|
5
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
6
|
+
var CosmosCoin_1 = require("../../CosmosCoin");
|
|
7
|
+
var CosmosMessage_1 = require("./CosmosMessage");
|
|
8
|
+
var CosmosDelegateMessage = /** @class */ (function () {
|
|
9
|
+
function CosmosDelegateMessage(delegatorAddress, validatorAddress, amount, undelegate) {
|
|
10
|
+
if (undelegate === void 0) { undelegate = false; }
|
|
11
|
+
this.delegatorAddress = delegatorAddress;
|
|
12
|
+
this.validatorAddress = validatorAddress;
|
|
13
|
+
this.amount = amount;
|
|
14
|
+
this.type = undelegate ? CosmosMessage_1.CosmosMessageType.Undelegate : CosmosMessage_1.CosmosMessageType.Delegate;
|
|
15
|
+
}
|
|
16
|
+
CosmosDelegateMessage.prototype.toEncodeObject = function () {
|
|
17
|
+
return {
|
|
18
|
+
typeUrl: this.type.value,
|
|
19
|
+
value: {
|
|
20
|
+
delegatorAddress: this.delegatorAddress,
|
|
21
|
+
validatorAddress: this.validatorAddress,
|
|
22
|
+
amount: this.amount
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
CosmosDelegateMessage.fromEncodeObject = function (encodeObject) {
|
|
27
|
+
var _a, _b, _c, _d;
|
|
28
|
+
var undelegate = encodeObject.typeUrl === CosmosMessage_1.CosmosMessageType.Undelegate.value;
|
|
29
|
+
return new CosmosDelegateMessage(encodeObject.value.delegatorAddress, encodeObject.value.validatorAddress, new CosmosCoin_1.CosmosCoin((_b = (_a = encodeObject.value.amount) === null || _a === void 0 ? void 0 : _a.denom) !== null && _b !== void 0 ? _b : 'uatom', (_d = (_c = encodeObject.value.amount) === null || _c === void 0 ? void 0 : _c.amount) !== null && _d !== void 0 ? _d : '0'), undelegate);
|
|
30
|
+
};
|
|
31
|
+
CosmosDelegateMessage.prototype.toJSON = function () {
|
|
32
|
+
return {
|
|
33
|
+
type: this.type.index,
|
|
34
|
+
amount: [this.amount.toJSON()],
|
|
35
|
+
fromAddress: this.delegatorAddress,
|
|
36
|
+
toAddress: this.validatorAddress
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
CosmosDelegateMessage.fromJSON = function (json) {
|
|
40
|
+
return new CosmosDelegateMessage(json.fromAddress, json.toAddress, CosmosCoin_1.CosmosCoin.fromJSON(json.amount[0]), json.type === CosmosMessage_1.CosmosMessageType.Undelegate.index);
|
|
41
|
+
};
|
|
42
|
+
CosmosDelegateMessage.prototype.toRPCBody = function () {
|
|
43
|
+
return {
|
|
44
|
+
type: this.type.value,
|
|
45
|
+
value: {
|
|
46
|
+
amount: this.amount.toRPCBody(),
|
|
47
|
+
delegator_address: this.delegatorAddress,
|
|
48
|
+
validator_address: this.validatorAddress
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
CosmosDelegateMessage.prototype.toAirGapTransaction = function (network, fee) {
|
|
53
|
+
return {
|
|
54
|
+
from: [this.delegatorAddress],
|
|
55
|
+
to: [this.validatorAddress],
|
|
56
|
+
isInbound: false,
|
|
57
|
+
amount: (0, module_kit_1.newAmount)(this.amount.amount, 'blockchain'),
|
|
58
|
+
fee: (0, module_kit_1.newAmount)(fee, 'blockchain'),
|
|
59
|
+
network: network,
|
|
60
|
+
type: this.type.index === CosmosMessage_1.CosmosMessageTypeIndex.DELEGATE ? IAirGapTransaction_1.AirGapTransactionType.DELEGATE : IAirGapTransaction_1.AirGapTransactionType.UNDELEGATE,
|
|
61
|
+
json: this.toRPCBody()
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
CosmosDelegateMessage.fromRPCBody = function (json) {
|
|
65
|
+
return new CosmosDelegateMessage(json.value.delegator_address, json.value.validator_address, CosmosCoin_1.CosmosCoin.fromRPCBody(json.value.amount), json.type === CosmosMessage_1.CosmosMessageType.Undelegate.value);
|
|
66
|
+
};
|
|
67
|
+
return CosmosDelegateMessage;
|
|
68
|
+
}());
|
|
69
|
+
exports.CosmosDelegateMessage = CosmosDelegateMessage;
|
|
70
|
+
//# sourceMappingURL=CosmosDelegateMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CosmosDelegateMessage.js","sourceRoot":"","sources":["../../../../../src/v1/data/transaction/message/CosmosDelegateMessage.ts"],"names":[],"mappings":";;;AACA,yFAA0F;AAC1F,iDAAiE;AAGjE,+CAA6C;AAE7C,iDAA6G;AAE7G;IAOE,+BAAY,gBAAwB,EAAE,gBAAwB,EAAE,MAAkB,EAAE,UAA2B;QAA3B,2BAAA,EAAA,kBAA2B;QAC7G,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAA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AD,CAAC,AAvFD,IAuFC;AAvFY,sDAAqB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { JSONConvertible } from '@airgap/coinlib-core/interfaces/JSONConvertible';
|
|
2
|
+
import { RPCConvertible } from '@airgap/coinlib-core/interfaces/RPCConvertible';
|
|
3
|
+
import { AirGapTransaction } from '@airgap/module-kit';
|
|
4
|
+
import { CosmosProtocolNetwork, CosmosUnits } from '../../../types/protocol';
|
|
5
|
+
import { CosmosCoinJSON } from '../../CosmosCoin';
|
|
6
|
+
import { Encodable } from '../CosmosTransaction';
|
|
7
|
+
export interface CosmosMessageJSON {
|
|
8
|
+
type: CosmosMessageTypeIndex;
|
|
9
|
+
amount: CosmosCoinJSON[];
|
|
10
|
+
fromAddress: string;
|
|
11
|
+
toAddress: string;
|
|
12
|
+
}
|
|
13
|
+
export declare enum CosmosMessageTypeIndex {
|
|
14
|
+
SEND = 0,
|
|
15
|
+
DELEGATE = 1,
|
|
16
|
+
UNDELEGATE = 2,
|
|
17
|
+
WITHDRAW_DELEGATION_REWARD = 3
|
|
18
|
+
}
|
|
19
|
+
export declare enum CosmosMessageTypeValue {
|
|
20
|
+
SEND = "/cosmos.bank.v1beta1.MsgSend",
|
|
21
|
+
DELEGATE = "/cosmos.staking.v1beta1.MsgDelegate",
|
|
22
|
+
UNDELEGATE = "/cosmos.staking.v1beta1.MsgUndelegate",
|
|
23
|
+
WITHDRAW_DELEGATION_REWARD = "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward"
|
|
24
|
+
}
|
|
25
|
+
export declare class CosmosMessageType {
|
|
26
|
+
static Send: CosmosMessageType;
|
|
27
|
+
static Delegate: CosmosMessageType;
|
|
28
|
+
static Undelegate: CosmosMessageType;
|
|
29
|
+
static WithdrawDelegationReward: CosmosMessageType;
|
|
30
|
+
readonly index: CosmosMessageTypeIndex;
|
|
31
|
+
readonly value: string;
|
|
32
|
+
constructor(index: CosmosMessageTypeIndex);
|
|
33
|
+
}
|
|
34
|
+
export interface CosmosMessage extends JSONConvertible, RPCConvertible, Encodable {
|
|
35
|
+
type: CosmosMessageType;
|
|
36
|
+
toAirGapTransaction(network: CosmosProtocolNetwork, fee: string): AirGapTransaction<CosmosUnits>;
|
|
37
|
+
toJSON(): CosmosMessageJSON;
|
|
38
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CosmosMessageType = exports.CosmosMessageTypeValue = exports.CosmosMessageTypeIndex = void 0;
|
|
4
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
5
|
+
var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
|
|
6
|
+
var CosmosMessageTypeIndex;
|
|
7
|
+
(function (CosmosMessageTypeIndex) {
|
|
8
|
+
CosmosMessageTypeIndex[CosmosMessageTypeIndex["SEND"] = 0] = "SEND";
|
|
9
|
+
CosmosMessageTypeIndex[CosmosMessageTypeIndex["DELEGATE"] = 1] = "DELEGATE";
|
|
10
|
+
CosmosMessageTypeIndex[CosmosMessageTypeIndex["UNDELEGATE"] = 2] = "UNDELEGATE";
|
|
11
|
+
CosmosMessageTypeIndex[CosmosMessageTypeIndex["WITHDRAW_DELEGATION_REWARD"] = 3] = "WITHDRAW_DELEGATION_REWARD";
|
|
12
|
+
})(CosmosMessageTypeIndex = exports.CosmosMessageTypeIndex || (exports.CosmosMessageTypeIndex = {}));
|
|
13
|
+
var CosmosMessageTypeValue;
|
|
14
|
+
(function (CosmosMessageTypeValue) {
|
|
15
|
+
CosmosMessageTypeValue["SEND"] = "/cosmos.bank.v1beta1.MsgSend";
|
|
16
|
+
CosmosMessageTypeValue["DELEGATE"] = "/cosmos.staking.v1beta1.MsgDelegate";
|
|
17
|
+
CosmosMessageTypeValue["UNDELEGATE"] = "/cosmos.staking.v1beta1.MsgUndelegate";
|
|
18
|
+
CosmosMessageTypeValue["WITHDRAW_DELEGATION_REWARD"] = "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward";
|
|
19
|
+
})(CosmosMessageTypeValue = exports.CosmosMessageTypeValue || (exports.CosmosMessageTypeValue = {}));
|
|
20
|
+
var CosmosMessageType = /** @class */ (function () {
|
|
21
|
+
function CosmosMessageType(index) {
|
|
22
|
+
this.index = index;
|
|
23
|
+
switch (index) {
|
|
24
|
+
case CosmosMessageTypeIndex.SEND:
|
|
25
|
+
this.value = CosmosMessageTypeValue.SEND;
|
|
26
|
+
break;
|
|
27
|
+
case CosmosMessageTypeIndex.DELEGATE:
|
|
28
|
+
this.value = CosmosMessageTypeValue.DELEGATE;
|
|
29
|
+
break;
|
|
30
|
+
case CosmosMessageTypeIndex.UNDELEGATE:
|
|
31
|
+
this.value = CosmosMessageTypeValue.UNDELEGATE;
|
|
32
|
+
break;
|
|
33
|
+
case CosmosMessageTypeIndex.WITHDRAW_DELEGATION_REWARD:
|
|
34
|
+
this.value = CosmosMessageTypeValue.WITHDRAW_DELEGATION_REWARD;
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.COSMOS, 'Unknown message');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
CosmosMessageType.Send = new CosmosMessageType(CosmosMessageTypeIndex.SEND);
|
|
41
|
+
CosmosMessageType.Delegate = new CosmosMessageType(CosmosMessageTypeIndex.DELEGATE);
|
|
42
|
+
CosmosMessageType.Undelegate = new CosmosMessageType(CosmosMessageTypeIndex.UNDELEGATE);
|
|
43
|
+
CosmosMessageType.WithdrawDelegationReward = new CosmosMessageType(CosmosMessageTypeIndex.WITHDRAW_DELEGATION_REWARD);
|
|
44
|
+
return CosmosMessageType;
|
|
45
|
+
}());
|
|
46
|
+
exports.CosmosMessageType = CosmosMessageType;
|
|
47
|
+
//# sourceMappingURL=CosmosMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CosmosMessage.js","sourceRoot":"","sources":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,IAAI,iBAAiB,CAAC,sBAAsB,CAAC,UAAU,CAAC,CAAA;IACxF,0CAAwB,GAAsB,IAAI,iBAAiB,CAAC,sBAAsB,CAAC,0BAA0B,CAAC,CAAA;IAwBtI,wBAAC;CAAA,AA5BD,IA4BC;AA5BY,8CAAiB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EncodeObject } from '@airgap/coinlib-core/dependencies/src/cosmjs';
|
|
2
|
+
import { AirGapTransaction } from '@airgap/module-kit';
|
|
3
|
+
import { CosmosProtocolNetwork, CosmosUnits } from '../../../types/protocol';
|
|
4
|
+
import { CosmosCoin } from '../../CosmosCoin';
|
|
5
|
+
import { CosmosMessage, CosmosMessageJSON, CosmosMessageType } from './CosmosMessage';
|
|
6
|
+
export declare class CosmosSendMessage implements CosmosMessage {
|
|
7
|
+
readonly fromAddress: string;
|
|
8
|
+
readonly toAddress: string;
|
|
9
|
+
readonly amount: CosmosCoin[];
|
|
10
|
+
readonly type: CosmosMessageType;
|
|
11
|
+
constructor(fromAddress: string, toAddress: string, amount: CosmosCoin[]);
|
|
12
|
+
toEncodeObject(): EncodeObject;
|
|
13
|
+
static fromEncodeObject(encodeObject: EncodeObject): CosmosSendMessage;
|
|
14
|
+
toJSON(): CosmosMessageJSON;
|
|
15
|
+
static fromJSON(json: CosmosMessageJSON): CosmosSendMessage;
|
|
16
|
+
toRPCBody(): any;
|
|
17
|
+
toAirGapTransaction(network: CosmosProtocolNetwork, fee: string): AirGapTransaction<CosmosUnits>;
|
|
18
|
+
static fromRPCBody(json: any): CosmosSendMessage;
|
|
19
|
+
}
|