@getpara/cosmjs-v0-integration 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./cosmosSigners.js"), exports);
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});
Binary file
Binary file
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export * from './cosmosSigners.js';
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};
Binary file
Binary file
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@getpara/cosmjs-v0-integration",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
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.2.0"
10
+ "@getpara/core-sdk": "1.3.1"
11
11
  },
12
12
  "scripts": {
13
- "build": "yarn build:cjs && yarn build:esm && yarn build:types",
13
+ "build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
14
+ "old-build": "yarn build:cjs && yarn build:esm && yarn build:types",
14
15
  "build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
15
16
  "build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
16
17
  "build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration"
@@ -31,5 +32,5 @@
31
32
  "dist",
32
33
  "package.json"
33
34
  ],
34
- "gitHead": "a9162c59be1456292d46c56787c1d5bf313bf24b"
35
+ "gitHead": "a35e01b55fde3220d50ead988b1c18f8442a9db4"
35
36
  }
@@ -1,108 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ParaAminoSigner = exports.ParaProtoSigner = void 0;
13
- const amino_1 = require("@cosmjs/amino");
14
- const crypto_1 = require("@cosmjs/crypto");
15
- const proto_signing_1 = require("@cosmjs/proto-signing");
16
- const tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
17
- const core_sdk_1 = require("@getpara/core-sdk");
18
- class ParaCosmosSigner {
19
- /**
20
- * Signs a message.
21
- *
22
- * @param para - the ParaCore instance
23
- * @param prefix - the cosmos address prefix, defaults to 'cosmos'
24
- * @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
25
- * @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
26
- **/
27
- constructor(para, prefix = 'cosmos', walletId, messageSigningTimeoutMs) {
28
- this.currentWalletId = para.findWalletId(walletId, { type: ['COSMOS'] });
29
- this.para = para;
30
- this.prefix = prefix;
31
- this.messageSigningTimeoutMs = messageSigningTimeoutMs;
32
- }
33
- get currentWallet() {
34
- var _a;
35
- return ((_a = this.para.wallets[this.currentWalletId]) !== null && _a !== void 0 ? _a : (() => {
36
- throw new Error(`no valid Para wallet found`);
37
- })());
38
- }
39
- get publicKey() {
40
- const uncompressedPublicKey = (0, core_sdk_1.hexToUint8Array)(this.currentWallet.publicKey);
41
- const compressedPublicKey = crypto_1.Secp256k1.compressPubkey(uncompressedPublicKey);
42
- return compressedPublicKey;
43
- }
44
- get address() {
45
- return (0, core_sdk_1.getCosmosAddress)(this.currentWallet.publicKey, this.prefix);
46
- }
47
- getAccounts() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- return [
50
- {
51
- algo: 'secp256k1',
52
- address: this.address,
53
- pubkey: this.publicKey,
54
- },
55
- ];
56
- });
57
- }
58
- }
59
- class ParaProtoSigner extends ParaCosmosSigner {
60
- signDirect(address, signDoc) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const signBytes = (0, proto_signing_1.makeSignBytes)(signDoc);
63
- if (address !== this.address) {
64
- throw new Error(`Address ${address} not found in wallet`);
65
- }
66
- const hashedMessage = (0, crypto_1.sha256)(signBytes);
67
- const signDocJson = tx_1.SignDoc.toJSON(signDoc);
68
- const signDocJsonStringified = JSON.stringify(signDocJson);
69
- const signDocJsonStringEncoded = btoa(signDocJsonStringified);
70
- const res = yield this.para.signMessage({
71
- walletId: this.currentWallet.id,
72
- messageBase64: Buffer.from(hashedMessage.buffer).toString('base64'),
73
- timeoutMs: this.messageSigningTimeoutMs,
74
- cosmosSignDocBase64: signDocJsonStringEncoded,
75
- });
76
- const signature = (0, core_sdk_1.hexToSignature)(`0x${res.signature}`);
77
- const extendedSignature = new crypto_1.ExtendedSecp256k1Signature((0, core_sdk_1.hexToUint8Array)(signature.r), (0, core_sdk_1.hexToUint8Array)(signature.s), Number(signature.v));
78
- const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
79
- return {
80
- signed: signDoc,
81
- signature: (0, amino_1.encodeSecp256k1Signature)(this.publicKey, signatureBytes),
82
- };
83
- });
84
- }
85
- }
86
- exports.ParaProtoSigner = ParaProtoSigner;
87
- class ParaAminoSigner extends ParaCosmosSigner {
88
- signAmino(signerAddress, signDoc) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- if (signerAddress !== this.address) {
91
- throw new Error(`Address ${signerAddress} not found in wallet`);
92
- }
93
- const hashedMessage = new crypto_1.Sha256((0, amino_1.serializeSignDoc)(signDoc)).digest();
94
- const res = yield this.para.signMessage({
95
- walletId: this.currentWallet.id,
96
- messageBase64: Buffer.from(hashedMessage.buffer).toString('base64'),
97
- });
98
- const signature = (0, core_sdk_1.hexToSignature)(`0x${res.signature}`);
99
- const extendedSignature = new crypto_1.ExtendedSecp256k1Signature((0, core_sdk_1.hexToUint8Array)(signature.r), (0, core_sdk_1.hexToUint8Array)(signature.s), Number(signature.v));
100
- const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
101
- return {
102
- signed: signDoc,
103
- signature: (0, amino_1.encodeSecp256k1Signature)(this.publicKey, signatureBytes),
104
- };
105
- });
106
- }
107
- }
108
- exports.ParaAminoSigner = ParaAminoSigner;
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,103 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { encodeSecp256k1Signature, serializeSignDoc, } from '@cosmjs/amino';
11
- import { Secp256k1, Sha256, sha256, ExtendedSecp256k1Signature } from '@cosmjs/crypto';
12
- import { makeSignBytes } from '@cosmjs/proto-signing';
13
- import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
14
- import { hexToSignature, hexToUint8Array, getCosmosAddress, } from '@getpara/core-sdk';
15
- class ParaCosmosSigner {
16
- /**
17
- * Signs a message.
18
- *
19
- * @param para - the ParaCore instance
20
- * @param prefix - the cosmos address prefix, defaults to 'cosmos'
21
- * @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
22
- * @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
23
- **/
24
- constructor(para, prefix = 'cosmos', walletId, messageSigningTimeoutMs) {
25
- this.currentWalletId = para.findWalletId(walletId, { type: ['COSMOS'] });
26
- this.para = para;
27
- this.prefix = prefix;
28
- this.messageSigningTimeoutMs = messageSigningTimeoutMs;
29
- }
30
- get currentWallet() {
31
- var _a;
32
- return ((_a = this.para.wallets[this.currentWalletId]) !== null && _a !== void 0 ? _a : (() => {
33
- throw new Error(`no valid Para wallet found`);
34
- })());
35
- }
36
- get publicKey() {
37
- const uncompressedPublicKey = hexToUint8Array(this.currentWallet.publicKey);
38
- const compressedPublicKey = Secp256k1.compressPubkey(uncompressedPublicKey);
39
- return compressedPublicKey;
40
- }
41
- get address() {
42
- return getCosmosAddress(this.currentWallet.publicKey, this.prefix);
43
- }
44
- getAccounts() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- return [
47
- {
48
- algo: 'secp256k1',
49
- address: this.address,
50
- pubkey: this.publicKey,
51
- },
52
- ];
53
- });
54
- }
55
- }
56
- export class ParaProtoSigner extends ParaCosmosSigner {
57
- signDirect(address, signDoc) {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- const signBytes = makeSignBytes(signDoc);
60
- if (address !== this.address) {
61
- throw new Error(`Address ${address} not found in wallet`);
62
- }
63
- const hashedMessage = sha256(signBytes);
64
- const signDocJson = SignDoc.toJSON(signDoc);
65
- const signDocJsonStringified = JSON.stringify(signDocJson);
66
- const signDocJsonStringEncoded = btoa(signDocJsonStringified);
67
- const res = yield this.para.signMessage({
68
- walletId: this.currentWallet.id,
69
- messageBase64: Buffer.from(hashedMessage.buffer).toString('base64'),
70
- timeoutMs: this.messageSigningTimeoutMs,
71
- cosmosSignDocBase64: signDocJsonStringEncoded,
72
- });
73
- const signature = hexToSignature(`0x${res.signature}`);
74
- const extendedSignature = new ExtendedSecp256k1Signature(hexToUint8Array(signature.r), hexToUint8Array(signature.s), Number(signature.v));
75
- const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
76
- return {
77
- signed: signDoc,
78
- signature: encodeSecp256k1Signature(this.publicKey, signatureBytes),
79
- };
80
- });
81
- }
82
- }
83
- export class ParaAminoSigner extends ParaCosmosSigner {
84
- signAmino(signerAddress, signDoc) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- if (signerAddress !== this.address) {
87
- throw new Error(`Address ${signerAddress} not found in wallet`);
88
- }
89
- const hashedMessage = new Sha256(serializeSignDoc(signDoc)).digest();
90
- const res = yield this.para.signMessage({
91
- walletId: this.currentWallet.id,
92
- messageBase64: Buffer.from(hashedMessage.buffer).toString('base64'),
93
- });
94
- const signature = hexToSignature(`0x${res.signature}`);
95
- const extendedSignature = new ExtendedSecp256k1Signature(hexToUint8Array(signature.r), hexToUint8Array(signature.s), Number(signature.v));
96
- const signatureBytes = new Uint8Array([...extendedSignature.r(32), ...extendedSignature.s(32)]);
97
- return {
98
- signed: signDoc,
99
- signature: encodeSecp256k1Signature(this.publicKey, signatureBytes),
100
- };
101
- });
102
- }
103
- }
@@ -1 +0,0 @@
1
- {"type":"module","sideEffects":false}