Skip to content

Commit

Permalink
Merge pull request #485 from mystic-lab/main
Browse files Browse the repository at this point in the history
Fix type error
  • Loading branch information
pyramation authored Jun 28, 2024
2 parents 0706f47 + 57fad89 commit df58797
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions wallets/cosmos-extension-metamask/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
"dependencies": {
"@chain-registry/keplr": "1.68.2",
"@cosmos-kit/core": "^2.13.0",
"@cosmsnap/snapper": "^0.2.3",
"@cosmsnap/snapper": "^0.2.4",
"cosmjs-types": ">=0.9.0"
},
"peerDependencies": {
"@cosmjs/amino": ">=0.32.3",
"@cosmjs/proto-signing": ">=0.32.3"
},
"gitHead": "2b5f2de5d9ed1580be4137736dfc6cce779679d1"
}
}
57 changes: 37 additions & 20 deletions wallets/cosmos-extension-metamask/src/extension/client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { OfflineAminoSigner, StdSignature, StdSignDoc } from '@cosmjs/amino';
import { Algo } from '@cosmjs/proto-signing';
import { Algo, DirectSignResponse, OfflineDirectSigner } from '@cosmjs/proto-signing';
import { ChainRecord, DirectSignDoc, SignType } from '@cosmos-kit/core';
import { SignOptions, WalletClient } from '@cosmos-kit/core';
import {
Chain,
CosmJSOfflineSigner,
CosmosSnap,
installSnap,
signDirect,
signAmino,
suggestChain,
} from '@cosmsnap/snapper';
import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
Expand Down Expand Up @@ -64,24 +65,14 @@ export class CosmosExtensionClient implements WalletClient {
default:
return this.getOfflineSignerAmino(chainId);
}
// return this.client.getOfflineSignerAuto(chainId);
}

getOfflineSignerAmino(chainId: string) {
return new CosmJSOfflineSigner(chainId) as unknown as OfflineAminoSigner;
return this.cosmos.getOfflineSigner(chainId, "amino") as unknown as OfflineAminoSigner;
}

getOfflineSignerDirect(chainId: string) {
return {
getAccounts: async () => {
return [await this.getAccount(chainId)];
},
signDirect: async (signerAddress: string, signDoc: SignDoc) =>
await this.signDirect(chainId, signerAddress, {
...signDoc,
accountNumber: BigInt(signDoc.accountNumber.toInt()),
}),
};
return this.cosmos.getOfflineSigner(chainId, "direct") as unknown as OfflineDirectSigner;
}

async signAmino(
Expand All @@ -90,7 +81,7 @@ export class CosmosExtensionClient implements WalletClient {
signDoc: StdSignDoc,
signOptions?: SignOptions
) {
return await this.cosmos.signAmino(chainId, signer, signDoc);
return await signAmino(chainId, signer, signDoc);
}

async signArbitrary(
Expand All @@ -107,10 +98,36 @@ export class CosmosExtensionClient implements WalletClient {
signer: string,
signDoc: DirectSignDoc,
signOptions?: SignOptions
) {
return await this.cosmos.signDirect(chainId, signer, {
...signDoc,
accountNumber: new Long(Number(signDoc.accountNumber.toString())),
});
): Promise<DirectSignResponse> {
if (chainId !== signDoc.chainId) {
throw new Error('Chain IDs do not match.');
}

const { accountNumber } = signDoc;

const accountNumberLong = Long.fromString(accountNumber.toString());

const newSignDoc: SignDoc = {
bodyBytes: signDoc.bodyBytes,
authInfoBytes: signDoc.authInfoBytes,
chainId: signDoc.chainId,
accountNumber: accountNumberLong
};

let signRes = await signDirect(chainId, signer, newSignDoc);

const sign = {
signature: signRes.signature,
signed: {
...signRes.signed,
accountNumber: accountNumberLong,
authInfoBytes: new Uint8Array(
Object.values(signRes.signed.authInfoBytes),
),
bodyBytes: new Uint8Array(Object.values(signRes.signed.bodyBytes)),
},
};

return sign;
}
}

0 comments on commit df58797

Please sign in to comment.