-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement signArbitrary for MockKeplr #1066
Comments
I believe this would almost completely suffice: 222bd16, except for the bech32 prefix in the verification function |
@LaurensKubat Hello. I'll check about it! Thank you. |
Hello. It would be nice if it could be changed to something like this, please check. import {
encodeSecp256k1Pubkey,
makeADR36AminoSignDoc,
verifyADR36Amino,
} from "@keplr-wallet/cosmos";
async signArbitrary(
chainId: string,
signer: string,
data: string | Uint8Array
): Promise<StdSignature> {
const wallet = await this.getWallet(chainId);
const key = await this.getKey(chainId);
if (signer !== key.bech32Address) {
throw new Error("Unmatched signer");
}
const signature = wallet.signDigest32(
Hash.sha256(serializeSignDoc(makeADR36AminoSignDoc(signer, data)))
);
return {
pub_key: encodeSecp256k1Pubkey(wallet.getPubKey().toBytes()),
signature: encodeSecp256k1Signature(
wallet.getPubKey().toBytes(),
new Uint8Array([...signature.r, ...signature.s])
).signature,
};
}
async verifyArbitrary(
chainId: string,
signer: string,
data: string | Uint8Array,
signature: StdSignature
): Promise<boolean> {
const wallet = await this.getWallet(chainId);
const key = await this.getKey(chainId);
if (signer !== key.bech32Address) {
throw new Error("Unmatched signer");
}
return verifyADR36Amino(
this.chainInfos.find((c) => c.chainId === chainId)!.bech32Config
.bech32PrefixAccAddr,
signer,
data,
wallet.getPubKey().toBytes(),
Buffer.from(signature.signature, "base64")
);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Currently,
MockKeplr
supportssignDirect
andsignAmino
, but throws a"Not implemented"
error forsignArbitrary
andverifyArbitrary
, making the testing of certain features that want to use adr-36 more difficult, especially in CI/CD environmentsDescribe the solution you'd like
Implement
signArbitrary
andverifyArbitrary
forMockKeplr
Describe alternatives you've considered
Inlining signArbitrary and signing using
MockKeplr
throughsignAmino
does not work due to type constraints. signArbitrary internally calls appears to callserializeSignDoc
internally. This behaviour is also seen in the verification functions ofverifyADR36AminoSignDoc
Additional context
I believe most code can be copy pasted from pre-existing adr36 code already within keplr, such as the verification funtions
The text was updated successfully, but these errors were encountered: