@getpara/cosmjs-v0-integration 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +127 -1
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js +107 -1
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1,127 @@
|
|
|
1
|
-
var
|
|
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
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
ParaAminoSigner: () => ParaAminoSigner,
|
|
23
|
+
ParaProtoSigner: () => ParaProtoSigner
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/cosmosSigners.ts
|
|
28
|
+
var import_amino = require("@cosmjs/amino");
|
|
29
|
+
var import_crypto = require("@cosmjs/crypto");
|
|
30
|
+
var import_proto_signing = require("@cosmjs/proto-signing");
|
|
31
|
+
var import_tx = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
32
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
33
|
+
var ParaCosmosSigner = class {
|
|
34
|
+
/**
|
|
35
|
+
* Signs a message.
|
|
36
|
+
*
|
|
37
|
+
* @param para - the ParaCore instance
|
|
38
|
+
* @param prefix - the cosmos address prefix, defaults to 'cosmos'
|
|
39
|
+
* @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
|
|
40
|
+
* @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
41
|
+
**/
|
|
42
|
+
constructor(para, prefix = "cosmos", walletId, messageSigningTimeoutMs) {
|
|
43
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["COSMOS"] });
|
|
44
|
+
this.para = para;
|
|
45
|
+
this.prefix = prefix;
|
|
46
|
+
this.messageSigningTimeoutMs = messageSigningTimeoutMs;
|
|
47
|
+
}
|
|
48
|
+
get currentWallet() {
|
|
49
|
+
return this.para.wallets[this.currentWalletId] ?? (() => {
|
|
50
|
+
throw new Error(`no valid Para wallet found`);
|
|
51
|
+
})();
|
|
52
|
+
}
|
|
53
|
+
get publicKey() {
|
|
54
|
+
const uncompressedPublicKey = (0, import_core_sdk.hexToUint8Array)(this.currentWallet.publicKey);
|
|
55
|
+
const compressedPublicKey = import_crypto.Secp256k1.compressPubkey(uncompressedPublicKey);
|
|
56
|
+
return compressedPublicKey;
|
|
57
|
+
}
|
|
58
|
+
get address() {
|
|
59
|
+
return (0, import_core_sdk.getCosmosAddress)(this.currentWallet.publicKey, this.prefix);
|
|
60
|
+
}
|
|
61
|
+
async getAccounts() {
|
|
62
|
+
return [
|
|
63
|
+
{
|
|
64
|
+
algo: "secp256k1",
|
|
65
|
+
address: this.address,
|
|
66
|
+
pubkey: this.publicKey
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var ParaProtoSigner = class extends ParaCosmosSigner {
|
|
72
|
+
async signDirect(address, signDoc) {
|
|
73
|
+
const signBytes = (0, import_proto_signing.makeSignBytes)(signDoc);
|
|
74
|
+
if (address !== this.address) {
|
|
75
|
+
throw new Error(`Address ${address} not found in wallet`);
|
|
76
|
+
}
|
|
77
|
+
const hashedMessage = (0, import_crypto.sha256)(signBytes);
|
|
78
|
+
const signDocJson = import_tx.SignDoc.toJSON(signDoc);
|
|
79
|
+
const signDocJsonStringified = JSON.stringify(signDocJson);
|
|
80
|
+
const signDocJsonStringEncoded = btoa(signDocJsonStringified);
|
|
81
|
+
const res = await this.para.signMessage({
|
|
82
|
+
walletId: this.currentWallet.id,
|
|
83
|
+
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64"),
|
|
84
|
+
timeoutMs: this.messageSigningTimeoutMs,
|
|
85
|
+
cosmosSignDocBase64: signDocJsonStringEncoded
|
|
86
|
+
});
|
|
87
|
+
const signature = (0, import_core_sdk.hexToSignature)(`0x${res.signature}`);
|
|
88
|
+
const extendedSignature = new import_crypto.ExtendedSecp256k1Signature(
|
|
89
|
+
(0, import_core_sdk.hexToUint8Array)(signature.r),
|
|
90
|
+
(0, import_core_sdk.hexToUint8Array)(signature.s),
|
|
91
|
+
Number(signature.v)
|
|
92
|
+
);
|
|
93
|
+
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
94
|
+
return {
|
|
95
|
+
signed: signDoc,
|
|
96
|
+
signature: (0, import_amino.encodeSecp256k1Signature)(this.publicKey, signatureBytes)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var ParaAminoSigner = class extends ParaCosmosSigner {
|
|
101
|
+
async signAmino(signerAddress, signDoc) {
|
|
102
|
+
if (signerAddress !== this.address) {
|
|
103
|
+
throw new Error(`Address ${signerAddress} not found in wallet`);
|
|
104
|
+
}
|
|
105
|
+
const hashedMessage = new import_crypto.Sha256((0, import_amino.serializeSignDoc)(signDoc)).digest();
|
|
106
|
+
const res = await this.para.signMessage({
|
|
107
|
+
walletId: this.currentWallet.id,
|
|
108
|
+
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64")
|
|
109
|
+
});
|
|
110
|
+
const signature = (0, import_core_sdk.hexToSignature)(`0x${res.signature}`);
|
|
111
|
+
const extendedSignature = new import_crypto.ExtendedSecp256k1Signature(
|
|
112
|
+
(0, import_core_sdk.hexToUint8Array)(signature.r),
|
|
113
|
+
(0, import_core_sdk.hexToUint8Array)(signature.s),
|
|
114
|
+
Number(signature.v)
|
|
115
|
+
);
|
|
116
|
+
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
117
|
+
return {
|
|
118
|
+
signed: signDoc,
|
|
119
|
+
signature: (0, import_amino.encodeSecp256k1Signature)(this.publicKey, signatureBytes)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
124
|
+
0 && (module.exports = {
|
|
125
|
+
ParaAminoSigner,
|
|
126
|
+
ParaProtoSigner
|
|
127
|
+
});
|
package/dist/cjs/index.js.br
CHANGED
|
Binary file
|
package/dist/cjs/index.js.gz
CHANGED
|
Binary file
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,107 @@
|
|
|
1
|
-
|
|
1
|
+
// src/cosmosSigners.ts
|
|
2
|
+
import {
|
|
3
|
+
encodeSecp256k1Signature,
|
|
4
|
+
serializeSignDoc
|
|
5
|
+
} from "@cosmjs/amino";
|
|
6
|
+
import { Secp256k1, Sha256, sha256, ExtendedSecp256k1Signature } from "@cosmjs/crypto";
|
|
7
|
+
import { makeSignBytes } from "@cosmjs/proto-signing";
|
|
8
|
+
import { SignDoc } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
9
|
+
import {
|
|
10
|
+
hexToSignature,
|
|
11
|
+
hexToUint8Array,
|
|
12
|
+
getCosmosAddress
|
|
13
|
+
} from "@getpara/core-sdk";
|
|
14
|
+
var ParaCosmosSigner = class {
|
|
15
|
+
/**
|
|
16
|
+
* Signs a message.
|
|
17
|
+
*
|
|
18
|
+
* @param para - the ParaCore instance
|
|
19
|
+
* @param prefix - the cosmos address prefix, defaults to 'cosmos'
|
|
20
|
+
* @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
|
|
21
|
+
* @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
22
|
+
**/
|
|
23
|
+
constructor(para, prefix = "cosmos", walletId, messageSigningTimeoutMs) {
|
|
24
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["COSMOS"] });
|
|
25
|
+
this.para = para;
|
|
26
|
+
this.prefix = prefix;
|
|
27
|
+
this.messageSigningTimeoutMs = messageSigningTimeoutMs;
|
|
28
|
+
}
|
|
29
|
+
get currentWallet() {
|
|
30
|
+
return this.para.wallets[this.currentWalletId] ?? (() => {
|
|
31
|
+
throw new Error(`no valid Para wallet found`);
|
|
32
|
+
})();
|
|
33
|
+
}
|
|
34
|
+
get publicKey() {
|
|
35
|
+
const uncompressedPublicKey = hexToUint8Array(this.currentWallet.publicKey);
|
|
36
|
+
const compressedPublicKey = Secp256k1.compressPubkey(uncompressedPublicKey);
|
|
37
|
+
return compressedPublicKey;
|
|
38
|
+
}
|
|
39
|
+
get address() {
|
|
40
|
+
return getCosmosAddress(this.currentWallet.publicKey, this.prefix);
|
|
41
|
+
}
|
|
42
|
+
async getAccounts() {
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
algo: "secp256k1",
|
|
46
|
+
address: this.address,
|
|
47
|
+
pubkey: this.publicKey
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var ParaProtoSigner = class extends ParaCosmosSigner {
|
|
53
|
+
async signDirect(address, signDoc) {
|
|
54
|
+
const signBytes = makeSignBytes(signDoc);
|
|
55
|
+
if (address !== this.address) {
|
|
56
|
+
throw new Error(`Address ${address} not found in wallet`);
|
|
57
|
+
}
|
|
58
|
+
const hashedMessage = sha256(signBytes);
|
|
59
|
+
const signDocJson = SignDoc.toJSON(signDoc);
|
|
60
|
+
const signDocJsonStringified = JSON.stringify(signDocJson);
|
|
61
|
+
const signDocJsonStringEncoded = btoa(signDocJsonStringified);
|
|
62
|
+
const res = await this.para.signMessage({
|
|
63
|
+
walletId: this.currentWallet.id,
|
|
64
|
+
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64"),
|
|
65
|
+
timeoutMs: this.messageSigningTimeoutMs,
|
|
66
|
+
cosmosSignDocBase64: signDocJsonStringEncoded
|
|
67
|
+
});
|
|
68
|
+
const signature = hexToSignature(`0x${res.signature}`);
|
|
69
|
+
const extendedSignature = new ExtendedSecp256k1Signature(
|
|
70
|
+
hexToUint8Array(signature.r),
|
|
71
|
+
hexToUint8Array(signature.s),
|
|
72
|
+
Number(signature.v)
|
|
73
|
+
);
|
|
74
|
+
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
75
|
+
return {
|
|
76
|
+
signed: signDoc,
|
|
77
|
+
signature: encodeSecp256k1Signature(this.publicKey, signatureBytes)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var ParaAminoSigner = class extends ParaCosmosSigner {
|
|
82
|
+
async signAmino(signerAddress, signDoc) {
|
|
83
|
+
if (signerAddress !== this.address) {
|
|
84
|
+
throw new Error(`Address ${signerAddress} not found in wallet`);
|
|
85
|
+
}
|
|
86
|
+
const hashedMessage = new Sha256(serializeSignDoc(signDoc)).digest();
|
|
87
|
+
const res = await this.para.signMessage({
|
|
88
|
+
walletId: this.currentWallet.id,
|
|
89
|
+
messageBase64: Buffer.from(hashedMessage.buffer).toString("base64")
|
|
90
|
+
});
|
|
91
|
+
const signature = hexToSignature(`0x${res.signature}`);
|
|
92
|
+
const extendedSignature = new ExtendedSecp256k1Signature(
|
|
93
|
+
hexToUint8Array(signature.r),
|
|
94
|
+
hexToUint8Array(signature.s),
|
|
95
|
+
Number(signature.v)
|
|
96
|
+
);
|
|
97
|
+
const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
|
|
98
|
+
return {
|
|
99
|
+
signed: signDoc,
|
|
100
|
+
signature: encodeSecp256k1Signature(this.publicKey, signatureBytes)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
export {
|
|
105
|
+
ParaAminoSigner,
|
|
106
|
+
ParaProtoSigner
|
|
107
|
+
};
|
package/dist/esm/index.js.br
CHANGED
|
Binary file
|
package/dist/esm/index.js.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/cosmjs-v0-integration",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
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
|
-
"@getpara/core-sdk": "1.4.
|
|
10
|
+
"@getpara/core-sdk": "1.4.4"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"dist",
|
|
33
33
|
"package.json"
|
|
34
34
|
],
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "9a4086c4b352fff2143d3b931d288c5ebaf127fb"
|
|
36
36
|
}
|