@getpara/cosmjs-v0-integration 1.4.2 → 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 CHANGED
@@ -1 +1,127 @@
1
- var m=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var W=(r,e)=>{for(var s in e)m(r,s,{get:e[s],enumerable:!0})},B=(r,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of A(e))!D.call(r,t)&&t!==s&&m(r,t,{get:()=>e[t],enumerable:!(o=x(e,t))||o.enumerable});return r};var K=r=>B(m({},"__esModule",{value:!0}),r);var M={};W(M,{ParaAminoSigner:()=>f,ParaProtoSigner:()=>S});module.exports=K(M);var c=require("@cosmjs/amino"),i=require("@cosmjs/crypto"),h=require("@cosmjs/proto-signing"),y=require("cosmjs-types/cosmos/tx/v1beta1/tx"),n=require("@getpara/core-sdk"),u=class{constructor(e,s="cosmos",o,t){this.currentWalletId=e.findWalletId(o,{type:["COSMOS"]}),this.para=e,this.prefix=s,this.messageSigningTimeoutMs=t}get currentWallet(){return this.para.wallets[this.currentWalletId]??(()=>{throw new Error("no valid Para wallet found")})()}get publicKey(){let e=(0,n.hexToUint8Array)(this.currentWallet.publicKey);return i.Secp256k1.compressPubkey(e)}get address(){return(0,n.getCosmosAddress)(this.currentWallet.publicKey,this.prefix)}async getAccounts(){return[{algo:"secp256k1",address:this.address,pubkey:this.publicKey}]}},S=class extends u{async signDirect(e,s){let o=(0,h.makeSignBytes)(s);if(e!==this.address)throw new Error(`Address ${e} not found in wallet`);let t=(0,i.sha256)(o),a=y.SignDoc.toJSON(s),g=JSON.stringify(a),l=btoa(g),b=await this.para.signMessage({walletId:this.currentWallet.id,messageBase64:Buffer.from(t.buffer).toString("base64"),timeoutMs:this.messageSigningTimeoutMs,cosmosSignDocBase64:l}),d=(0,n.hexToSignature)(`0x${b.signature}`),p=new i.ExtendedSecp256k1Signature((0,n.hexToUint8Array)(d.r),(0,n.hexToUint8Array)(d.s),Number(d.v)),w=new Uint8Array([...p.r(32),...p.s(32)]);return{signed:s,signature:(0,c.encodeSecp256k1Signature)(this.publicKey,w)}}},f=class extends u{async signAmino(e,s){if(e!==this.address)throw new Error(`Address ${e} not found in wallet`);let o=new i.Sha256((0,c.serializeSignDoc)(s)).digest(),t=await this.para.signMessage({walletId:this.currentWallet.id,messageBase64:Buffer.from(o.buffer).toString("base64")}),a=(0,n.hexToSignature)(`0x${t.signature}`),g=new i.ExtendedSecp256k1Signature((0,n.hexToUint8Array)(a.r),(0,n.hexToUint8Array)(a.s),Number(a.v)),l=new Uint8Array([...g.r(32),...g.s(32)]);return{signed:s,signature:(0,c.encodeSecp256k1Signature)(this.publicKey,l)}}};0&&(module.exports={ParaAminoSigner,ParaProtoSigner});
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
+ });
Binary file
Binary file
package/dist/esm/index.js CHANGED
@@ -1 +1,107 @@
1
- import{encodeSecp256k1Signature as S,serializeSignDoc as b}from"@cosmjs/amino";import{Secp256k1 as w,Sha256 as x,sha256 as A,ExtendedSecp256k1Signature as f}from"@cosmjs/crypto";import{makeSignBytes as D}from"@cosmjs/proto-signing";import{SignDoc as W}from"cosmjs-types/cosmos/tx/v1beta1/tx";import{hexToSignature as p,hexToUint8Array as i,getCosmosAddress as B}from"@getpara/core-sdk";var a=class{constructor(e,s="cosmos",t,n){this.currentWalletId=e.findWalletId(t,{type:["COSMOS"]}),this.para=e,this.prefix=s,this.messageSigningTimeoutMs=n}get currentWallet(){return this.para.wallets[this.currentWalletId]??(()=>{throw new Error("no valid Para wallet found")})()}get publicKey(){let e=i(this.currentWallet.publicKey);return w.compressPubkey(e)}get address(){return B(this.currentWallet.publicKey,this.prefix)}async getAccounts(){return[{algo:"secp256k1",address:this.address,pubkey:this.publicKey}]}},d=class extends a{async signDirect(e,s){let t=D(s);if(e!==this.address)throw new Error(`Address ${e} not found in wallet`);let n=A(t),r=W.toJSON(s),o=JSON.stringify(r),c=btoa(o),h=await this.para.signMessage({walletId:this.currentWallet.id,messageBase64:Buffer.from(n.buffer).toString("base64"),timeoutMs:this.messageSigningTimeoutMs,cosmosSignDocBase64:c}),g=p(`0x${h.signature}`),l=new f(i(g.r),i(g.s),Number(g.v)),y=new Uint8Array([...l.r(32),...l.s(32)]);return{signed:s,signature:S(this.publicKey,y)}}},m=class extends a{async signAmino(e,s){if(e!==this.address)throw new Error(`Address ${e} not found in wallet`);let t=new x(b(s)).digest(),n=await this.para.signMessage({walletId:this.currentWallet.id,messageBase64:Buffer.from(t.buffer).toString("base64")}),r=p(`0x${n.signature}`),o=new f(i(r.r),i(r.s),Number(r.v)),c=new Uint8Array([...o.r(32),...o.s(32)]);return{signed:s,signature:S(this.publicKey,c)}}};export{m as ParaAminoSigner,d as ParaProtoSigner};
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
+ };
Binary file
Binary file
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@getpara/cosmjs-v0-integration",
3
- "version": "1.4.2",
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.2"
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": "8404d1f8461109347360fe21be6057f826d31cec"
35
+ "gitHead": "9a4086c4b352fff2143d3b931d288c5ebaf127fb"
36
36
  }