Skip to content

Commit 24f630a

Browse files
authored
Merge pull request #21 from SigmaGmbH/BLOCK-357_vesting-proto
Vesting proto added
2 parents 8fdfa1a + c2caada commit 24f630a

File tree

8 files changed

+1033
-227
lines changed

8 files changed

+1033
-227
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@swisstronik/sdk",
3-
"version": "1.14.0",
3+
"version": "1.15.0",
44
"description": "TypeScript SDK for Swisstronik Network",
55
"license": "Apache-2.0",
66
"source": "src/index.ts",

packages/sdk/src/client.ts

Lines changed: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
1-
import { Uint64 } from "@cosmjs/math";
21
import {
32
Account,
43
AccountParser,
54
StargateClient,
65
StargateClientOptions,
76
} from "@cosmjs/stargate";
8-
import { EthAccount } from "./types-proto/ethermint/types/v1/account.js";
97
import { Tendermint34Client, Tendermint37Client } from "@cosmjs/tendermint-rpc";
10-
import {
11-
encodeSecp256k1Pubkey,
12-
Pubkey,
13-
SinglePubkey,
14-
encodeEd25519Pubkey,
15-
MultisigThresholdPubkey,
16-
} from "@cosmjs/amino";
17-
import { Any } from "./types-proto/google/protobuf/any.js";
18-
import Long from "long";
19-
import { PubKey as CosmosCryptoEd25519Pubkey } from "cosmjs-types/cosmos/crypto/ed25519/keys.js";
20-
import { PubKey as CosmosCryptoSecp256k1Pubkey } from "cosmjs-types/cosmos/crypto/secp256k1/keys.js";
21-
import { PubKey as CommonPubKey } from "cosmjs-types/cosmos/crypto/secp256k1/keys.js";
22-
import { Secp256k1 } from "./compatability/secp256k1.js";
23-
import { LegacyAminoPubKey } from "cosmjs-types/cosmos/crypto/multisig/keys.js";
248
import {
259
QueryAddressDetailsRequest,
2610
QueryAddressDetailsResponse,
@@ -40,6 +24,7 @@ import {
4024
QueryVerificationListResponse,
4125
} from "./compliance/verificationDetails.js";
4226
import { PageRequest } from "cosmjs-types/cosmos/base/query/v1beta1/pagination.js";
27+
import { accountFromAny } from "./utils.js";
4328
export class SwisstronikStargateClient extends StargateClient {
4429
private readonly overridenAccountParser: AccountParser;
4530

@@ -49,7 +34,7 @@ export class SwisstronikStargateClient extends StargateClient {
4934
) {
5035
super(tmClient, options);
5136

52-
const { accountParser = this.accountFromAny } = options;
37+
const { accountParser = accountFromAny } = options;
5338
this.overridenAccountParser = accountParser;
5439
}
5540

@@ -59,7 +44,7 @@ export class SwisstronikStargateClient extends StargateClient {
5944
) {
6045
// Tendermint/CometBFT 0.34/0.37 auto-detection. Starting with 0.37 we seem to get reliable versions again 🎉
6146
// Using 0.34 as the fallback.
62-
let tmClient;
47+
let tmClient: Tendermint37Client | Tendermint34Client;
6348
const tm37Client = await Tendermint37Client.connect(endpoint);
6449
const version = (await tm37Client.status()).nodeInfo.version;
6550
console.log(`[sdk::client.ts] Detected Tendermint version: ${version}`);
@@ -91,75 +76,6 @@ export class SwisstronikStargateClient extends StargateClient {
9176
}
9277
}
9378

94-
private accountFromAny(input: Any): Account {
95-
console.log("[DEBUG] Using overriden account parser");
96-
console.log("[DEBUG] Input - ", input);
97-
const { value } = input;
98-
console.log("DEBUG: value to decode", Buffer.from(value).toString("hex"));
99-
const account = EthAccount.decode(value);
100-
console.log("[DEBUG] account", account);
101-
const { address, pubKey, accountNumber, sequence } = account.baseAccount!;
102-
const pubkey = pubKey ? this.decodePubkey(pubKey) : null;
103-
return {
104-
address: address,
105-
pubkey: pubkey,
106-
accountNumber: this.uint64FromProto(accountNumber).toNumber(),
107-
sequence: this.uint64FromProto(sequence).toNumber(),
108-
};
109-
}
110-
111-
private uint64FromProto(input: number | Long): Uint64 {
112-
return Uint64.fromString(input.toString());
113-
}
114-
115-
private decodePubkey(pubkey: Any): Pubkey {
116-
switch (pubkey.typeUrl) {
117-
case "/ethermint.crypto.v1.ethsecp256k1.PubKey":
118-
case "/cosmos.crypto.secp256k1.PubKey":
119-
case "/cosmos.crypto.ed25519.PubKey": {
120-
return this.anyToSinglePubkey(pubkey);
121-
}
122-
case "/cosmos.crypto.multisig.LegacyAminoPubKey": {
123-
return this.anyToMultiPubkey(pubkey);
124-
}
125-
default:
126-
throw new Error(`Pubkey type_url ${pubkey.typeUrl} not recognized`);
127-
}
128-
}
129-
130-
private anyToMultiPubkey(pubkey: Any): MultisigThresholdPubkey {
131-
const { publicKeys, threshold } = LegacyAminoPubKey.decode(pubkey.value);
132-
const keys = publicKeys.map((key) => this.anyToSinglePubkey(key));
133-
return {
134-
type: "tendermint/PubKeyMultisigThreshold",
135-
value: {
136-
pubkeys: keys,
137-
threshold: String(threshold),
138-
},
139-
};
140-
}
141-
142-
private anyToSinglePubkey(pubkey: Any): SinglePubkey {
143-
switch (pubkey.typeUrl) {
144-
case "/ethermint.crypto.v1.ethsecp256k1.PubKey":
145-
const { key } = CommonPubKey.decode(pubkey.value);
146-
const compressedKey = Secp256k1.compressPubkey(key);
147-
return encodeSecp256k1Pubkey(compressedKey);
148-
case "/cosmos.crypto.secp256k1.PubKey": {
149-
const { key } = CosmosCryptoSecp256k1Pubkey.decode(pubkey.value);
150-
return encodeSecp256k1Pubkey(key);
151-
}
152-
case "/cosmos.crypto.ed25519.PubKey": {
153-
const { key } = CosmosCryptoEd25519Pubkey.decode(pubkey.value);
154-
return encodeEd25519Pubkey(key);
155-
}
156-
default:
157-
throw new Error(
158-
`Pubkey type_url ${pubkey.typeUrl} not recognized as single public key type`
159-
);
160-
}
161-
}
162-
16379
public async queryAddressDetails(address: string) {
16480
const response = await this.forceGetTmClient().abciQuery({
16581
path: `/swisstronik.compliance.Query/AddressDetails`,

packages/sdk/src/signer.ts

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
makeSignDoc,
66
makeAuthInfoBytes,
77
} from "@cosmjs/proto-signing"
8-
import { Uint64 } from "@cosmjs/math";
98
import {
109
DeliverTxResponse,
1110
GasPrice,
@@ -18,9 +17,9 @@ import {
1817
SequenceResponse,
1918
SignerData,
2019
AminoTypes,
21-
createDefaultAminoConverters
20+
createDefaultAminoConverters,
21+
accountFromAny
2222
} from "@cosmjs/stargate"
23-
import { EthAccount } from "./types-proto/ethermint/types/v1/account.js";
2423
import { Tendermint34Client, Tendermint37Client } from "@cosmjs/tendermint-rpc"
2524
import { createDefaultIdentityRegistry } from "./registry.js"
2625
import {
@@ -48,7 +47,7 @@ import {
4847
assert,
4948
assertDefined
5049
} from '@cosmjs/utils'
51-
import { encodeSecp256k1Pubkey, Pubkey, SinglePubkey, encodeEd25519Pubkey, StdFee, makeSignDoc as makeSignDocAmino, MultisigThresholdPubkey } from '@cosmjs/amino'
50+
import { StdFee, makeSignDoc as makeSignDocAmino } from '@cosmjs/amino'
5251
import { Int53 } from '@cosmjs/math'
5352
import { fromBase64 } from '@cosmjs/encoding'
5453
import {
@@ -60,11 +59,7 @@ import { SignMode } from 'cosmjs-types/cosmos/tx/signing/v1beta1/signing.js'
6059
import {Any } from './types-proto/google/protobuf/any.js'
6160
import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin.js'
6261
import Long from 'long'
63-
import { PubKey as CosmosCryptoEd25519Pubkey } from "cosmjs-types/cosmos/crypto/ed25519/keys.js";
64-
import { PubKey as CosmosCryptoSecp256k1Pubkey } from "cosmjs-types/cosmos/crypto/secp256k1/keys.js";
6562
import { PubKey as CommonPubKey } from "cosmjs-types/cosmos/crypto/secp256k1/keys.js";
66-
import { Secp256k1 } from "./compatability/secp256k1.js";
67-
import {LegacyAminoPubKey} from "cosmjs-types/cosmos/crypto/multisig/keys.js"
6863
import {
6964
QueryAddressDetailsRequest,
7065
QueryAddressDetailsResponse,
@@ -169,7 +164,7 @@ export class SwisstronikSigningStargateClient extends SigningStargateClient {
169164
this._signer = signer
170165
if (options.gasPrice) this._gasPrice = options.gasPrice
171166

172-
const { accountParser = this.accountFromAny, aminoTypes = new AminoTypes(createDefaultAminoConverters()), } = options;
167+
const { accountParser = accountFromAny, aminoTypes = new AminoTypes(createDefaultAminoConverters()), } = options;
173168
this.overridenAccountParser = accountParser;
174169
this._aminoTypes = aminoTypes;
175170
}
@@ -432,74 +427,6 @@ export class SwisstronikSigningStargateClient extends SigningStargateClient {
432427
return signInfos
433428
}
434429

435-
private accountFromAny(input: Any): Account {
436-
console.log('[DEBUG] Using overriden account parser')
437-
console.log('[DEBUG] Input - ', input)
438-
const { value } = input
439-
console.log('DEBUG: value to decode', Buffer.from(value).toString('hex'))
440-
const account = EthAccount.decode(value)
441-
console.log('[DEBUG] account', account)
442-
const { address, pubKey, accountNumber, sequence } = account.baseAccount!;
443-
const pubkey = pubKey ? this.decodePubkey(pubKey) : null;
444-
return {
445-
address: address,
446-
pubkey: pubkey,
447-
accountNumber: this.uint64FromProto(accountNumber).toNumber(),
448-
sequence: this.uint64FromProto(sequence).toNumber(),
449-
};
450-
}
451-
452-
private uint64FromProto(input: number | Long): Uint64 {
453-
return Uint64.fromString(input.toString());
454-
}
455-
456-
private decodePubkey(pubkey: Any): Pubkey {
457-
switch (pubkey.typeUrl) {
458-
case "/ethermint.crypto.v1.ethsecp256k1.PubKey":
459-
case "/cosmos.crypto.secp256k1.PubKey":
460-
case "/cosmos.crypto.ed25519.PubKey": {
461-
return this.anyToSinglePubkey(pubkey);
462-
}
463-
case "/cosmos.crypto.multisig.LegacyAminoPubKey": {
464-
return this.anyToMultiPubkey(pubkey);
465-
}
466-
default:
467-
throw new Error(`Pubkey type_url ${pubkey.typeUrl} not recognized`);
468-
}
469-
}
470-
471-
private anyToMultiPubkey(pubkey: Any): MultisigThresholdPubkey {
472-
const { publicKeys, threshold } = LegacyAminoPubKey.decode(pubkey.value);
473-
const keys = publicKeys.map((key) => this.anyToSinglePubkey(key));
474-
return {
475-
type: "tendermint/PubKeyMultisigThreshold",
476-
value: {
477-
pubkeys: keys,
478-
threshold: String(threshold)
479-
},
480-
};
481-
}
482-
483-
private anyToSinglePubkey(pubkey: Any): SinglePubkey {
484-
switch (pubkey.typeUrl) {
485-
case "/ethermint.crypto.v1.ethsecp256k1.PubKey":
486-
const { key } = CommonPubKey.decode(pubkey.value);
487-
const compressedKey = Secp256k1.compressPubkey(key);
488-
return encodeSecp256k1Pubkey(compressedKey);
489-
case "/cosmos.crypto.secp256k1.PubKey": {
490-
const { key } = CosmosCryptoSecp256k1Pubkey.decode(pubkey.value);
491-
return encodeSecp256k1Pubkey(key);
492-
}
493-
case "/cosmos.crypto.ed25519.PubKey": {
494-
const { key } = CosmosCryptoEd25519Pubkey.decode(pubkey.value);
495-
return encodeEd25519Pubkey(key);
496-
}
497-
default:
498-
throw new Error(`Pubkey type_url ${pubkey.typeUrl} not recognized as single public key type`);
499-
}
500-
}
501-
502-
503430
public async queryAddressDetails(address: string) {
504431
const response = await this.forceGetTmClient().abciQuery({
505432
path: `/swisstronik.compliance.Query/AddressDetails`,

0 commit comments

Comments
 (0)