@getpara/cosmjs-v0-integration 2.0.0-alpha.3 → 2.0.0-alpha.6
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/cjs/cosmosSigners.js +150 -0
- package/dist/cjs/index.js +5 -136
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/utils.js +94 -0
- package/dist/esm/chunk-4AFQP74Z.js +24 -0
- package/dist/esm/cosmosSigners.js +116 -0
- package/dist/esm/index.js +2 -135
- package/dist/esm/package.json +4 -0
- package/dist/esm/utils.js +54 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils.d.ts +10 -0
- package/package.json +4 -3
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var cosmosSigners_exports = {};
|
|
39
|
+
__export(cosmosSigners_exports, {
|
|
40
|
+
ParaAminoSigner: () => ParaAminoSigner,
|
|
41
|
+
ParaProtoSigner: () => ParaProtoSigner
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(cosmosSigners_exports);
|
|
44
|
+
var import_amino = require("@cosmjs/amino");
|
|
45
|
+
var import_crypto = require("@cosmjs/crypto");
|
|
46
|
+
var import_proto_signing = require("@cosmjs/proto-signing");
|
|
47
|
+
var import_tx = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
48
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
49
|
+
class ParaCosmosSigner {
|
|
50
|
+
/**
|
|
51
|
+
* Signs a message.
|
|
52
|
+
*
|
|
53
|
+
* @param para - the ParaCore instance
|
|
54
|
+
* @param prefix - the cosmos address prefix, defaults to 'cosmos'
|
|
55
|
+
* @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
|
|
56
|
+
* @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
57
|
+
**/
|
|
58
|
+
constructor(para, prefix = "cosmos", walletId, messageSigningTimeoutMs) {
|
|
59
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["COSMOS"] });
|
|
60
|
+
this.para = para;
|
|
61
|
+
this.prefix = prefix;
|
|
62
|
+
this.messageSigningTimeoutMs = messageSigningTimeoutMs;
|
|
63
|
+
}
|
|
64
|
+
get currentWallet() {
|
|
65
|
+
var _a;
|
|
66
|
+
return (_a = this.para.wallets[this.currentWalletId]) != null ? _a : (() => {
|
|
67
|
+
throw new Error(`no valid Para wallet found`);
|
|
68
|
+
})();
|
|
69
|
+
}
|
|
70
|
+
get publicKey() {
|
|
71
|
+
const uncompressedPublicKey = (0, import_core_sdk.hexToUint8Array)(this.currentWallet.publicKey);
|
|
72
|
+
const compressedPublicKey = import_crypto.Secp256k1.compressPubkey(uncompressedPublicKey);
|
|
73
|
+
return compressedPublicKey;
|
|
74
|
+
}
|
|
75
|
+
get address() {
|
|
76
|
+
return (0, import_core_sdk.getCosmosAddress)(this.currentWallet.publicKey, this.prefix);
|
|
77
|
+
}
|
|
78
|
+
getAccounts() {
|
|
79
|
+
return __async(this, null, function* () {
|
|
80
|
+
return [
|
|
81
|
+
{
|
|
82
|
+
algo: "secp256k1",
|
|
83
|
+
address: this.address,
|
|
84
|
+
pubkey: this.publicKey
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class ParaProtoSigner extends ParaCosmosSigner {
|
|
91
|
+
signDirect(address, signDoc) {
|
|
92
|
+
return __async(this, null, function* () {
|
|
93
|
+
const signBytes = (0, import_proto_signing.makeSignBytes)(signDoc);
|
|
94
|
+
if (address !== this.address) {
|
|
95
|
+
throw new Error(`Address ${address} not found in wallet`);
|
|
96
|
+
}
|
|
97
|
+
const hashedMessage = (0, import_crypto.sha256)(signBytes);
|
|
98
|
+
const signDocJson = import_tx.SignDoc.toJSON(signDoc);
|
|
99
|
+
const signDocJsonStringified = JSON.stringify(signDocJson);
|
|
100
|
+
const signDocJsonStringEncoded = btoa(signDocJsonStringified);
|
|
101
|
+
const res = yield this.para.signMessage({
|
|
102
|
+
walletId: this.currentWallet.id,
|
|
103
|
+
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64"),
|
|
104
|
+
timeoutMs: this.messageSigningTimeoutMs,
|
|
105
|
+
cosmosSignDocBase64: signDocJsonStringEncoded
|
|
106
|
+
});
|
|
107
|
+
const signature = (0, import_core_sdk.hexToSignature)(`0x${res.signature}`);
|
|
108
|
+
const extendedSignature = new import_crypto.ExtendedSecp256k1Signature(
|
|
109
|
+
(0, import_core_sdk.hexToUint8Array)(signature.r),
|
|
110
|
+
(0, import_core_sdk.hexToUint8Array)(signature.s),
|
|
111
|
+
Number(signature.v)
|
|
112
|
+
);
|
|
113
|
+
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
114
|
+
return {
|
|
115
|
+
signed: signDoc,
|
|
116
|
+
signature: (0, import_amino.encodeSecp256k1Signature)(this.publicKey, signatureBytes)
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
class ParaAminoSigner extends ParaCosmosSigner {
|
|
122
|
+
signAmino(signerAddress, signDoc) {
|
|
123
|
+
return __async(this, null, function* () {
|
|
124
|
+
if (signerAddress !== this.address) {
|
|
125
|
+
throw new Error(`Address ${signerAddress} not found in wallet`);
|
|
126
|
+
}
|
|
127
|
+
const hashedMessage = new import_crypto.Sha256((0, import_amino.serializeSignDoc)(signDoc)).digest();
|
|
128
|
+
const res = yield this.para.signMessage({
|
|
129
|
+
walletId: this.currentWallet.id,
|
|
130
|
+
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64")
|
|
131
|
+
});
|
|
132
|
+
const signature = (0, import_core_sdk.hexToSignature)(`0x${res.signature}`);
|
|
133
|
+
const extendedSignature = new import_crypto.ExtendedSecp256k1Signature(
|
|
134
|
+
(0, import_core_sdk.hexToUint8Array)(signature.r),
|
|
135
|
+
(0, import_core_sdk.hexToUint8Array)(signature.s),
|
|
136
|
+
Number(signature.v)
|
|
137
|
+
);
|
|
138
|
+
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
139
|
+
return {
|
|
140
|
+
signed: signDoc,
|
|
141
|
+
signature: (0, import_amino.encodeSecp256k1Signature)(this.publicKey, signatureBytes)
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
147
|
+
0 && (module.exports = {
|
|
148
|
+
ParaAminoSigner,
|
|
149
|
+
ParaProtoSigner
|
|
150
|
+
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -2,10 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
5
|
var __copyProps = (to, from, except, desc) => {
|
|
10
6
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
7
|
for (let key of __getOwnPropNames(from))
|
|
@@ -14,141 +10,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
10
|
}
|
|
15
11
|
return to;
|
|
16
12
|
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
17
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var __async = (__this, __arguments, generator) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
var fulfilled = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.next(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var rejected = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.throw(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/index.ts
|
|
40
15
|
var src_exports = {};
|
|
41
|
-
__export(src_exports, {
|
|
42
|
-
ParaAminoSigner: () => ParaAminoSigner,
|
|
43
|
-
ParaProtoSigner: () => ParaProtoSigner
|
|
44
|
-
});
|
|
45
16
|
module.exports = __toCommonJS(src_exports);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var import_amino = require("@cosmjs/amino");
|
|
49
|
-
var import_crypto = require("@cosmjs/crypto");
|
|
50
|
-
var import_proto_signing = require("@cosmjs/proto-signing");
|
|
51
|
-
var import_tx = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
52
|
-
var import_core_sdk = require("@getpara/core-sdk");
|
|
53
|
-
var ParaCosmosSigner = class {
|
|
54
|
-
/**
|
|
55
|
-
* Signs a message.
|
|
56
|
-
*
|
|
57
|
-
* @param para - the ParaCore instance
|
|
58
|
-
* @param prefix - the cosmos address prefix, defaults to 'cosmos'
|
|
59
|
-
* @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
|
|
60
|
-
* @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
61
|
-
**/
|
|
62
|
-
constructor(para, prefix = "cosmos", walletId, messageSigningTimeoutMs) {
|
|
63
|
-
this.currentWalletId = para.findWalletId(walletId, { type: ["COSMOS"] });
|
|
64
|
-
this.para = para;
|
|
65
|
-
this.prefix = prefix;
|
|
66
|
-
this.messageSigningTimeoutMs = messageSigningTimeoutMs;
|
|
67
|
-
}
|
|
68
|
-
get currentWallet() {
|
|
69
|
-
var _a;
|
|
70
|
-
return (_a = this.para.wallets[this.currentWalletId]) != null ? _a : (() => {
|
|
71
|
-
throw new Error(`no valid Para wallet found`);
|
|
72
|
-
})();
|
|
73
|
-
}
|
|
74
|
-
get publicKey() {
|
|
75
|
-
const uncompressedPublicKey = (0, import_core_sdk.hexToUint8Array)(this.currentWallet.publicKey);
|
|
76
|
-
const compressedPublicKey = import_crypto.Secp256k1.compressPubkey(uncompressedPublicKey);
|
|
77
|
-
return compressedPublicKey;
|
|
78
|
-
}
|
|
79
|
-
get address() {
|
|
80
|
-
return (0, import_core_sdk.getCosmosAddress)(this.currentWallet.publicKey, this.prefix);
|
|
81
|
-
}
|
|
82
|
-
getAccounts() {
|
|
83
|
-
return __async(this, null, function* () {
|
|
84
|
-
return [
|
|
85
|
-
{
|
|
86
|
-
algo: "secp256k1",
|
|
87
|
-
address: this.address,
|
|
88
|
-
pubkey: this.publicKey
|
|
89
|
-
}
|
|
90
|
-
];
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
var ParaProtoSigner = class extends ParaCosmosSigner {
|
|
95
|
-
signDirect(address, signDoc) {
|
|
96
|
-
return __async(this, null, function* () {
|
|
97
|
-
const signBytes = (0, import_proto_signing.makeSignBytes)(signDoc);
|
|
98
|
-
if (address !== this.address) {
|
|
99
|
-
throw new Error(`Address ${address} not found in wallet`);
|
|
100
|
-
}
|
|
101
|
-
const hashedMessage = (0, import_crypto.sha256)(signBytes);
|
|
102
|
-
const signDocJson = import_tx.SignDoc.toJSON(signDoc);
|
|
103
|
-
const signDocJsonStringified = JSON.stringify(signDocJson);
|
|
104
|
-
const signDocJsonStringEncoded = btoa(signDocJsonStringified);
|
|
105
|
-
const res = yield this.para.signMessage({
|
|
106
|
-
walletId: this.currentWallet.id,
|
|
107
|
-
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64"),
|
|
108
|
-
timeoutMs: this.messageSigningTimeoutMs,
|
|
109
|
-
cosmosSignDocBase64: signDocJsonStringEncoded
|
|
110
|
-
});
|
|
111
|
-
const signature = (0, import_core_sdk.hexToSignature)(`0x${res.signature}`);
|
|
112
|
-
const extendedSignature = new import_crypto.ExtendedSecp256k1Signature(
|
|
113
|
-
(0, import_core_sdk.hexToUint8Array)(signature.r),
|
|
114
|
-
(0, import_core_sdk.hexToUint8Array)(signature.s),
|
|
115
|
-
Number(signature.v)
|
|
116
|
-
);
|
|
117
|
-
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
118
|
-
return {
|
|
119
|
-
signed: signDoc,
|
|
120
|
-
signature: (0, import_amino.encodeSecp256k1Signature)(this.publicKey, signatureBytes)
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
var ParaAminoSigner = class extends ParaCosmosSigner {
|
|
126
|
-
signAmino(signerAddress, signDoc) {
|
|
127
|
-
return __async(this, null, function* () {
|
|
128
|
-
if (signerAddress !== this.address) {
|
|
129
|
-
throw new Error(`Address ${signerAddress} not found in wallet`);
|
|
130
|
-
}
|
|
131
|
-
const hashedMessage = new import_crypto.Sha256((0, import_amino.serializeSignDoc)(signDoc)).digest();
|
|
132
|
-
const res = yield this.para.signMessage({
|
|
133
|
-
walletId: this.currentWallet.id,
|
|
134
|
-
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64")
|
|
135
|
-
});
|
|
136
|
-
const signature = (0, import_core_sdk.hexToSignature)(`0x${res.signature}`);
|
|
137
|
-
const extendedSignature = new import_crypto.ExtendedSecp256k1Signature(
|
|
138
|
-
(0, import_core_sdk.hexToUint8Array)(signature.r),
|
|
139
|
-
(0, import_core_sdk.hexToUint8Array)(signature.s),
|
|
140
|
-
Number(signature.v)
|
|
141
|
-
);
|
|
142
|
-
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
143
|
-
return {
|
|
144
|
-
signed: signDoc,
|
|
145
|
-
signature: (0, import_amino.encodeSecp256k1Signature)(this.publicKey, signatureBytes)
|
|
146
|
-
};
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
};
|
|
17
|
+
__reExport(src_exports, require("./cosmosSigners.js"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./utils.js"), module.exports);
|
|
150
19
|
// Annotate the CommonJS export names for ESM import in node:
|
|
151
20
|
0 && (module.exports = {
|
|
152
|
-
|
|
153
|
-
|
|
21
|
+
...require("./cosmosSigners.js"),
|
|
22
|
+
...require("./utils.js")
|
|
154
23
|
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var utils_exports = {};
|
|
39
|
+
__export(utils_exports, {
|
|
40
|
+
createTestTransaction: () => createTestTransaction
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(utils_exports);
|
|
43
|
+
var import_stargate = require("@cosmjs/stargate");
|
|
44
|
+
var import_tx = require("cosmjs-types/cosmos/bank/v1beta1/tx");
|
|
45
|
+
var import_tx2 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
46
|
+
function createTestTransaction(para, walletId) {
|
|
47
|
+
return __async(this, null, function* () {
|
|
48
|
+
walletId = para.findWalletId(walletId, { type: ["COSMOS"] });
|
|
49
|
+
const wallet = para.wallets[walletId];
|
|
50
|
+
const address = para.getDisplayAddress(wallet.id, { addressType: "COSMOS" });
|
|
51
|
+
const client = yield import_stargate.StargateClient.connect("https://cosmos-rpc.publicnode.com:443");
|
|
52
|
+
const account = yield client.getAccount(address);
|
|
53
|
+
if (!account) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`You must fund this account with testnet ATOM tokens before you can sign transactions. Your address is ${address}. The testnet faucet can be found at: https://discord.com/channels/669268347736686612/953697793476821092`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const transaction = import_tx2.Tx.fromPartial({
|
|
59
|
+
body: {
|
|
60
|
+
messages: [
|
|
61
|
+
{
|
|
62
|
+
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
|
63
|
+
value: import_tx.MsgSend.encode(
|
|
64
|
+
import_tx.MsgSend.fromPartial({
|
|
65
|
+
fromAddress: address,
|
|
66
|
+
toAddress: address,
|
|
67
|
+
amount: [{ denom: "uatom", amount: "0.01" }]
|
|
68
|
+
})
|
|
69
|
+
).finish()
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
memo: ""
|
|
73
|
+
},
|
|
74
|
+
authInfo: {
|
|
75
|
+
fee: {
|
|
76
|
+
amount: [(0, import_stargate.coin)(5e3, "uatom")],
|
|
77
|
+
gasLimit: BigInt(8e4)
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
signatures: []
|
|
81
|
+
});
|
|
82
|
+
const signDoc = {
|
|
83
|
+
accountNumber: BigInt(account.accountNumber),
|
|
84
|
+
bodyBytes: import_tx2.TxBody.encode(transaction.body).finish(),
|
|
85
|
+
authInfoBytes: import_tx2.AuthInfo.encode(transaction.authInfo).finish(),
|
|
86
|
+
chainId: "theta-testnet-001"
|
|
87
|
+
};
|
|
88
|
+
return signDoc;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
createTestTransaction
|
|
94
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
__async
|
|
24
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async
|
|
3
|
+
} from "./chunk-4AFQP74Z.js";
|
|
4
|
+
import {
|
|
5
|
+
encodeSecp256k1Signature,
|
|
6
|
+
serializeSignDoc
|
|
7
|
+
} from "@cosmjs/amino";
|
|
8
|
+
import { Secp256k1, Sha256, sha256, ExtendedSecp256k1Signature } from "@cosmjs/crypto";
|
|
9
|
+
import { makeSignBytes } from "@cosmjs/proto-signing";
|
|
10
|
+
import { SignDoc } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
11
|
+
import {
|
|
12
|
+
hexToSignature,
|
|
13
|
+
hexToUint8Array,
|
|
14
|
+
getCosmosAddress
|
|
15
|
+
} from "@getpara/core-sdk";
|
|
16
|
+
class ParaCosmosSigner {
|
|
17
|
+
/**
|
|
18
|
+
* Signs a message.
|
|
19
|
+
*
|
|
20
|
+
* @param para - the ParaCore instance
|
|
21
|
+
* @param prefix - the cosmos address prefix, defaults to 'cosmos'
|
|
22
|
+
* @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
|
|
23
|
+
* @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
24
|
+
**/
|
|
25
|
+
constructor(para, prefix = "cosmos", walletId, messageSigningTimeoutMs) {
|
|
26
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["COSMOS"] });
|
|
27
|
+
this.para = para;
|
|
28
|
+
this.prefix = prefix;
|
|
29
|
+
this.messageSigningTimeoutMs = messageSigningTimeoutMs;
|
|
30
|
+
}
|
|
31
|
+
get currentWallet() {
|
|
32
|
+
var _a;
|
|
33
|
+
return (_a = this.para.wallets[this.currentWalletId]) != null ? _a : (() => {
|
|
34
|
+
throw new Error(`no valid Para wallet found`);
|
|
35
|
+
})();
|
|
36
|
+
}
|
|
37
|
+
get publicKey() {
|
|
38
|
+
const uncompressedPublicKey = hexToUint8Array(this.currentWallet.publicKey);
|
|
39
|
+
const compressedPublicKey = Secp256k1.compressPubkey(uncompressedPublicKey);
|
|
40
|
+
return compressedPublicKey;
|
|
41
|
+
}
|
|
42
|
+
get address() {
|
|
43
|
+
return getCosmosAddress(this.currentWallet.publicKey, this.prefix);
|
|
44
|
+
}
|
|
45
|
+
getAccounts() {
|
|
46
|
+
return __async(this, null, function* () {
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
algo: "secp256k1",
|
|
50
|
+
address: this.address,
|
|
51
|
+
pubkey: this.publicKey
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class ParaProtoSigner extends ParaCosmosSigner {
|
|
58
|
+
signDirect(address, signDoc) {
|
|
59
|
+
return __async(this, null, function* () {
|
|
60
|
+
const signBytes = makeSignBytes(signDoc);
|
|
61
|
+
if (address !== this.address) {
|
|
62
|
+
throw new Error(`Address ${address} not found in wallet`);
|
|
63
|
+
}
|
|
64
|
+
const hashedMessage = sha256(signBytes);
|
|
65
|
+
const signDocJson = SignDoc.toJSON(signDoc);
|
|
66
|
+
const signDocJsonStringified = JSON.stringify(signDocJson);
|
|
67
|
+
const signDocJsonStringEncoded = btoa(signDocJsonStringified);
|
|
68
|
+
const res = yield this.para.signMessage({
|
|
69
|
+
walletId: this.currentWallet.id,
|
|
70
|
+
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64"),
|
|
71
|
+
timeoutMs: this.messageSigningTimeoutMs,
|
|
72
|
+
cosmosSignDocBase64: signDocJsonStringEncoded
|
|
73
|
+
});
|
|
74
|
+
const signature = hexToSignature(`0x${res.signature}`);
|
|
75
|
+
const extendedSignature = new ExtendedSecp256k1Signature(
|
|
76
|
+
hexToUint8Array(signature.r),
|
|
77
|
+
hexToUint8Array(signature.s),
|
|
78
|
+
Number(signature.v)
|
|
79
|
+
);
|
|
80
|
+
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
81
|
+
return {
|
|
82
|
+
signed: signDoc,
|
|
83
|
+
signature: encodeSecp256k1Signature(this.publicKey, signatureBytes)
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
class ParaAminoSigner extends ParaCosmosSigner {
|
|
89
|
+
signAmino(signerAddress, signDoc) {
|
|
90
|
+
return __async(this, null, function* () {
|
|
91
|
+
if (signerAddress !== this.address) {
|
|
92
|
+
throw new Error(`Address ${signerAddress} not found in wallet`);
|
|
93
|
+
}
|
|
94
|
+
const hashedMessage = new Sha256(serializeSignDoc(signDoc)).digest();
|
|
95
|
+
const res = yield this.para.signMessage({
|
|
96
|
+
walletId: this.currentWallet.id,
|
|
97
|
+
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64")
|
|
98
|
+
});
|
|
99
|
+
const signature = hexToSignature(`0x${res.signature}`);
|
|
100
|
+
const extendedSignature = new ExtendedSecp256k1Signature(
|
|
101
|
+
hexToUint8Array(signature.r),
|
|
102
|
+
hexToUint8Array(signature.s),
|
|
103
|
+
Number(signature.v)
|
|
104
|
+
);
|
|
105
|
+
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
106
|
+
return {
|
|
107
|
+
signed: signDoc,
|
|
108
|
+
signature: encodeSecp256k1Signature(this.publicKey, signatureBytes)
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
ParaAminoSigner,
|
|
115
|
+
ParaProtoSigner
|
|
116
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,135 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/cosmosSigners.ts
|
|
23
|
-
import {
|
|
24
|
-
encodeSecp256k1Signature,
|
|
25
|
-
serializeSignDoc
|
|
26
|
-
} from "@cosmjs/amino";
|
|
27
|
-
import { Secp256k1, Sha256, sha256, ExtendedSecp256k1Signature } from "@cosmjs/crypto";
|
|
28
|
-
import { makeSignBytes } from "@cosmjs/proto-signing";
|
|
29
|
-
import { SignDoc } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
30
|
-
import {
|
|
31
|
-
hexToSignature,
|
|
32
|
-
hexToUint8Array,
|
|
33
|
-
getCosmosAddress
|
|
34
|
-
} from "@getpara/core-sdk";
|
|
35
|
-
var ParaCosmosSigner = class {
|
|
36
|
-
/**
|
|
37
|
-
* Signs a message.
|
|
38
|
-
*
|
|
39
|
-
* @param para - the ParaCore instance
|
|
40
|
-
* @param prefix - the cosmos address prefix, defaults to 'cosmos'
|
|
41
|
-
* @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
|
|
42
|
-
* @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
43
|
-
**/
|
|
44
|
-
constructor(para, prefix = "cosmos", walletId, messageSigningTimeoutMs) {
|
|
45
|
-
this.currentWalletId = para.findWalletId(walletId, { type: ["COSMOS"] });
|
|
46
|
-
this.para = para;
|
|
47
|
-
this.prefix = prefix;
|
|
48
|
-
this.messageSigningTimeoutMs = messageSigningTimeoutMs;
|
|
49
|
-
}
|
|
50
|
-
get currentWallet() {
|
|
51
|
-
var _a;
|
|
52
|
-
return (_a = this.para.wallets[this.currentWalletId]) != null ? _a : (() => {
|
|
53
|
-
throw new Error(`no valid Para wallet found`);
|
|
54
|
-
})();
|
|
55
|
-
}
|
|
56
|
-
get publicKey() {
|
|
57
|
-
const uncompressedPublicKey = hexToUint8Array(this.currentWallet.publicKey);
|
|
58
|
-
const compressedPublicKey = Secp256k1.compressPubkey(uncompressedPublicKey);
|
|
59
|
-
return compressedPublicKey;
|
|
60
|
-
}
|
|
61
|
-
get address() {
|
|
62
|
-
return getCosmosAddress(this.currentWallet.publicKey, this.prefix);
|
|
63
|
-
}
|
|
64
|
-
getAccounts() {
|
|
65
|
-
return __async(this, null, function* () {
|
|
66
|
-
return [
|
|
67
|
-
{
|
|
68
|
-
algo: "secp256k1",
|
|
69
|
-
address: this.address,
|
|
70
|
-
pubkey: this.publicKey
|
|
71
|
-
}
|
|
72
|
-
];
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var ParaProtoSigner = class extends ParaCosmosSigner {
|
|
77
|
-
signDirect(address, signDoc) {
|
|
78
|
-
return __async(this, null, function* () {
|
|
79
|
-
const signBytes = makeSignBytes(signDoc);
|
|
80
|
-
if (address !== this.address) {
|
|
81
|
-
throw new Error(`Address ${address} not found in wallet`);
|
|
82
|
-
}
|
|
83
|
-
const hashedMessage = sha256(signBytes);
|
|
84
|
-
const signDocJson = SignDoc.toJSON(signDoc);
|
|
85
|
-
const signDocJsonStringified = JSON.stringify(signDocJson);
|
|
86
|
-
const signDocJsonStringEncoded = btoa(signDocJsonStringified);
|
|
87
|
-
const res = yield this.para.signMessage({
|
|
88
|
-
walletId: this.currentWallet.id,
|
|
89
|
-
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64"),
|
|
90
|
-
timeoutMs: this.messageSigningTimeoutMs,
|
|
91
|
-
cosmosSignDocBase64: signDocJsonStringEncoded
|
|
92
|
-
});
|
|
93
|
-
const signature = hexToSignature(`0x${res.signature}`);
|
|
94
|
-
const extendedSignature = new ExtendedSecp256k1Signature(
|
|
95
|
-
hexToUint8Array(signature.r),
|
|
96
|
-
hexToUint8Array(signature.s),
|
|
97
|
-
Number(signature.v)
|
|
98
|
-
);
|
|
99
|
-
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
100
|
-
return {
|
|
101
|
-
signed: signDoc,
|
|
102
|
-
signature: encodeSecp256k1Signature(this.publicKey, signatureBytes)
|
|
103
|
-
};
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
var ParaAminoSigner = class extends ParaCosmosSigner {
|
|
108
|
-
signAmino(signerAddress, signDoc) {
|
|
109
|
-
return __async(this, null, function* () {
|
|
110
|
-
if (signerAddress !== this.address) {
|
|
111
|
-
throw new Error(`Address ${signerAddress} not found in wallet`);
|
|
112
|
-
}
|
|
113
|
-
const hashedMessage = new Sha256(serializeSignDoc(signDoc)).digest();
|
|
114
|
-
const res = yield this.para.signMessage({
|
|
115
|
-
walletId: this.currentWallet.id,
|
|
116
|
-
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64")
|
|
117
|
-
});
|
|
118
|
-
const signature = hexToSignature(`0x${res.signature}`);
|
|
119
|
-
const extendedSignature = new ExtendedSecp256k1Signature(
|
|
120
|
-
hexToUint8Array(signature.r),
|
|
121
|
-
hexToUint8Array(signature.s),
|
|
122
|
-
Number(signature.v)
|
|
123
|
-
);
|
|
124
|
-
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
125
|
-
return {
|
|
126
|
-
signed: signDoc,
|
|
127
|
-
signature: encodeSecp256k1Signature(this.publicKey, signatureBytes)
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
export {
|
|
133
|
-
ParaAminoSigner,
|
|
134
|
-
ParaProtoSigner
|
|
135
|
-
};
|
|
1
|
+
export * from "./cosmosSigners.js";
|
|
2
|
+
export * from "./utils.js";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async
|
|
3
|
+
} from "./chunk-4AFQP74Z.js";
|
|
4
|
+
import { coin, StargateClient } from "@cosmjs/stargate";
|
|
5
|
+
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
|
6
|
+
import { AuthInfo, Tx, TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
7
|
+
function createTestTransaction(para, walletId) {
|
|
8
|
+
return __async(this, null, function* () {
|
|
9
|
+
walletId = para.findWalletId(walletId, { type: ["COSMOS"] });
|
|
10
|
+
const wallet = para.wallets[walletId];
|
|
11
|
+
const address = para.getDisplayAddress(wallet.id, { addressType: "COSMOS" });
|
|
12
|
+
const client = yield StargateClient.connect("https://cosmos-rpc.publicnode.com:443");
|
|
13
|
+
const account = yield client.getAccount(address);
|
|
14
|
+
if (!account) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`You must fund this account with testnet ATOM tokens before you can sign transactions. Your address is ${address}. The testnet faucet can be found at: https://discord.com/channels/669268347736686612/953697793476821092`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
const transaction = Tx.fromPartial({
|
|
20
|
+
body: {
|
|
21
|
+
messages: [
|
|
22
|
+
{
|
|
23
|
+
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
|
24
|
+
value: MsgSend.encode(
|
|
25
|
+
MsgSend.fromPartial({
|
|
26
|
+
fromAddress: address,
|
|
27
|
+
toAddress: address,
|
|
28
|
+
amount: [{ denom: "uatom", amount: "0.01" }]
|
|
29
|
+
})
|
|
30
|
+
).finish()
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
memo: ""
|
|
34
|
+
},
|
|
35
|
+
authInfo: {
|
|
36
|
+
fee: {
|
|
37
|
+
amount: [coin(5e3, "uatom")],
|
|
38
|
+
gasLimit: BigInt(8e4)
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
signatures: []
|
|
42
|
+
});
|
|
43
|
+
const signDoc = {
|
|
44
|
+
accountNumber: BigInt(account.accountNumber),
|
|
45
|
+
bodyBytes: TxBody.encode(transaction.body).finish(),
|
|
46
|
+
authInfoBytes: AuthInfo.encode(transaction.authInfo).finish(),
|
|
47
|
+
chainId: "theta-testnet-001"
|
|
48
|
+
};
|
|
49
|
+
return signDoc;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
createTestTransaction
|
|
54
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ParaCore from '@getpara/core-sdk';
|
|
2
|
+
import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Cosmos transaction to sign and validate that your Para application is properly working.
|
|
5
|
+
* The transaction, if broadcast, simply sends 0.01 ATOM from the wallet back to itself.
|
|
6
|
+
* @param {ParaCore} para your Para instance
|
|
7
|
+
* @param {string} walletId the EVM wallet ID to use.
|
|
8
|
+
* @returns {Promise<SignDoc>} the generated Cosmos `SignDoc`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTestTransaction(para: ParaCore, walletId?: string): Promise<SignDoc>;
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/cosmjs-v0-integration",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.6",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
7
7
|
"typings": "dist/types/index.d.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@
|
|
10
|
+
"@cosmjs/stargate": "<=0.33.1",
|
|
11
|
+
"@getpara/core-sdk": "2.0.0-alpha.6"
|
|
11
12
|
},
|
|
12
13
|
"scripts": {
|
|
13
14
|
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
@@ -32,5 +33,5 @@
|
|
|
32
33
|
"dist",
|
|
33
34
|
"package.json"
|
|
34
35
|
],
|
|
35
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "d3b01a8fb475c2af9bf255800bc10d05e011b2eb"
|
|
36
37
|
}
|
package/dist/cjs/index.js.br
DELETED
|
Binary file
|
package/dist/cjs/index.js.gz
DELETED
|
Binary file
|
package/dist/esm/index.js.br
DELETED
|
Binary file
|
package/dist/esm/index.js.gz
DELETED
|
Binary file
|