proto-signing: Switch to fromPartial instead of fromJSON
This commit is contained in:
parent
c3b0292ffa
commit
d77230a2e1
@ -219,7 +219,7 @@ export const SignatureDescriptor = {
|
||||
fromJSON(object: any): SignatureDescriptor {
|
||||
const message = { ...baseSignatureDescriptor } as SignatureDescriptor;
|
||||
if (object.publicKey !== undefined && object.publicKey !== null) {
|
||||
message.publicKey = Any.fromJSON(object.publicKey);
|
||||
message.publicKey = Any.fromPartial(object.publicKey);
|
||||
} else {
|
||||
message.publicKey = undefined;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ describe("protobuf demo", () => {
|
||||
amount: [coin],
|
||||
});
|
||||
const msgSendBytes = MsgSend.encode(msgSend).finish();
|
||||
const msgSendWrapped = Any.fromJSON({
|
||||
const msgSendWrapped = Any.fromPartial({
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: msgSendBytes,
|
||||
});
|
||||
@ -64,7 +64,7 @@ describe("protobuf demo", () => {
|
||||
example: "Some example text",
|
||||
}) as unknown) as MsgDemo;
|
||||
const msgDemoBytes = encoder.encode(msgDemo).finish();
|
||||
const msgDemoWrapped = Any.fromJSON({
|
||||
const msgDemoWrapped = Any.fromPartial({
|
||||
typeUrl: typeUrl,
|
||||
value: msgDemoBytes,
|
||||
});
|
||||
@ -95,7 +95,7 @@ describe("protobuf demo", () => {
|
||||
example: "Some example text",
|
||||
}) as unknown) as MsgDemo;
|
||||
const msgDemoBytes = encoder.encode(msgDemo).finish();
|
||||
const msgDemoWrapped = Any.fromJSON({
|
||||
const msgDemoWrapped = Any.fromPartial({
|
||||
typeUrl: typeUrl,
|
||||
value: msgDemoBytes,
|
||||
});
|
||||
@ -125,7 +125,7 @@ describe("protobuf demo", () => {
|
||||
example: "Some example text",
|
||||
}) as unknown) as MsgDemo;
|
||||
const msgDemoBytes = encoder.encode(msgDemo).finish();
|
||||
const msgDemoWrapped = Any.fromJSON({
|
||||
const msgDemoWrapped = Any.fromPartial({
|
||||
typeUrl: typeUrl,
|
||||
value: msgDemoBytes,
|
||||
});
|
||||
|
||||
@ -13,7 +13,7 @@ describe("pubkey", () => {
|
||||
it("works for secp256k1", () => {
|
||||
const pubkey = { type: "tendermint/PubKeySecp256k1", value: defaultPubkeyBase64 };
|
||||
expect(encodePubkey(pubkey)).toEqual(
|
||||
Any.fromJSON({
|
||||
Any.fromPartial({
|
||||
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
||||
value: defaultPubkeyProtoBytes,
|
||||
}),
|
||||
|
||||
@ -8,10 +8,10 @@ import { Any } from "./codec/google/protobuf/any";
|
||||
export function encodePubkey(pubkey: LaunchpadPubKey): Any {
|
||||
switch (pubkey.type) {
|
||||
case "tendermint/PubKeySecp256k1": {
|
||||
const pubkeyProto = PubKey.fromJSON({
|
||||
const pubkeyProto = PubKey.fromPartial({
|
||||
key: fromBase64(pubkey.value),
|
||||
});
|
||||
return Any.fromJSON({
|
||||
return Any.fromPartial({
|
||||
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
||||
value: Uint8Array.from(PubKey.encode(pubkeyProto).finish()),
|
||||
});
|
||||
|
||||
@ -13,17 +13,17 @@ describe("registry demo", () => {
|
||||
const Coin = registry.lookupType("/cosmos.base.v1beta1.Coin")!;
|
||||
const MsgSend = registry.lookupType("/cosmos.bank.v1beta1.MsgSend")!;
|
||||
|
||||
const coin = Coin.fromJSON({
|
||||
const coin = Coin.fromPartial({
|
||||
denom: "ucosm",
|
||||
amount: "1234567890",
|
||||
});
|
||||
const msgSend = (MsgSend.fromJSON({
|
||||
const msgSend = (MsgSend.fromPartial({
|
||||
fromAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
toAddress: "cosmos1qypqxpq9qcrsszg2pvxq6rs0zqg3yyc5lzv7xu",
|
||||
amount: [coin],
|
||||
}) as unknown) as IMsgSend;
|
||||
const msgSendBytes = MsgSend.encode(msgSend).finish();
|
||||
const msgSendWrapped = Any.fromJSON({
|
||||
const msgSendWrapped = Any.fromPartial({
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: msgSendBytes,
|
||||
});
|
||||
@ -55,7 +55,7 @@ describe("registry demo", () => {
|
||||
// const registry = new Registry([[typeUrl, MsgDemoType]]);
|
||||
// const MsgDemo = registry.lookupType(typeUrl)!;
|
||||
|
||||
// const msgDemo = MsgDemo.fromJSON({
|
||||
// const msgDemo = MsgDemo.fromPartial({
|
||||
// example: "Some example text",
|
||||
// });
|
||||
// const msgDemoBytes = MsgDemo.encode(msgDemo).finish();
|
||||
|
||||
@ -80,7 +80,7 @@ export class Registry {
|
||||
public encodeTxBody(txBodyFields: TxBodyValue): Uint8Array {
|
||||
const wrappedMessages = txBodyFields.messages.map((message) => {
|
||||
const messageBytes = this.encode(message);
|
||||
return Any.fromJSON({
|
||||
return Any.fromPartial({
|
||||
typeUrl: message.typeUrl,
|
||||
value: messageBytes,
|
||||
});
|
||||
|
||||
@ -62,7 +62,7 @@ describe("signing", () => {
|
||||
const myRegistry = new Registry();
|
||||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic);
|
||||
const [{ address, pubkey: pubkeyBytes }] = await wallet.getAccounts();
|
||||
const publicKey = PubKey.fromJSON({
|
||||
const publicKey = PubKey.fromPartial({
|
||||
key: pubkeyBytes,
|
||||
});
|
||||
const publicKeyBytes = PubKey.encode(publicKey).finish();
|
||||
@ -89,7 +89,10 @@ describe("signing", () => {
|
||||
value: txBodyFields,
|
||||
});
|
||||
|
||||
const publicKeyAny = Any.fromJSON({ typeUrl: "/cosmos.crypto.secp256k1.PubKey", value: publicKeyBytes });
|
||||
const publicKeyAny = Any.fromPartial({
|
||||
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
||||
value: publicKeyBytes,
|
||||
});
|
||||
const accountNumber = 1;
|
||||
|
||||
await Promise.all(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user