Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/add-ledger-support-smart-ac…
Browse files Browse the repository at this point in the history
…count' into mattupham/fe-1077-v26-fe-tasks
  • Loading branch information
mattupham committed Sep 13, 2024
2 parents 83e0374 + 6c3b8fc commit 958ccdd
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { base64FromBytes, bytesFromBase64 } from "../../../helpers";
/** MsgAddAuthenticatorRequest defines the Msg/AddAuthenticator request type. */
export interface MsgAddAuthenticator {
sender: string;
type: string;
authenticatorType: string;
data: Uint8Array;
}
export interface MsgAddAuthenticatorProtoMsg {
Expand All @@ -14,7 +14,7 @@ export interface MsgAddAuthenticatorProtoMsg {
/** MsgAddAuthenticatorRequest defines the Msg/AddAuthenticator request type. */
export interface MsgAddAuthenticatorAmino {
sender?: string;
type?: string;
authenticator_type?: string;
data?: string;
}
export interface MsgAddAuthenticatorAminoMsg {
Expand All @@ -24,7 +24,7 @@ export interface MsgAddAuthenticatorAminoMsg {
/** MsgAddAuthenticatorRequest defines the Msg/AddAuthenticator request type. */
export interface MsgAddAuthenticatorSDKType {
sender: string;
type: string;
authenticator_type: string;
data: Uint8Array;
}
/** MsgAddAuthenticatorResponse defines the Msg/AddAuthenticator response type. */
Expand Down Expand Up @@ -189,7 +189,7 @@ export interface TxExtensionSDKType {
function createBaseMsgAddAuthenticator(): MsgAddAuthenticator {
return {
sender: "",
type: "",
authenticatorType: "",
data: new Uint8Array(),
};
}
Expand All @@ -202,8 +202,8 @@ export const MsgAddAuthenticator = {
if (message.sender !== "") {
writer.uint32(10).string(message.sender);
}
if (message.type !== "") {
writer.uint32(18).string(message.type);
if (message.authenticatorType !== "") {
writer.uint32(18).string(message.authenticatorType);
}
if (message.data.length !== 0) {
writer.uint32(26).bytes(message.data);
Expand All @@ -225,7 +225,7 @@ export const MsgAddAuthenticator = {
message.sender = reader.string();
break;
case 2:
message.type = reader.string();
message.authenticatorType = reader.string();
break;
case 3:
message.data = reader.bytes();
Expand All @@ -240,7 +240,7 @@ export const MsgAddAuthenticator = {
fromPartial(object: Partial<MsgAddAuthenticator>): MsgAddAuthenticator {
const message = createBaseMsgAddAuthenticator();
message.sender = object.sender ?? "";
message.type = object.type ?? "";
message.authenticatorType = object.authenticatorType ?? "";
message.data = object.data ?? new Uint8Array();
return message;
},
Expand All @@ -249,8 +249,11 @@ export const MsgAddAuthenticator = {
if (object.sender !== undefined && object.sender !== null) {
message.sender = object.sender;
}
if (object.type !== undefined && object.type !== null) {
message.type = object.type;
if (
object.authenticator_type !== undefined &&
object.authenticator_type !== null
) {
message.authenticatorType = object.authenticator_type;
}
if (object.data !== undefined && object.data !== null) {
message.data = bytesFromBase64(object.data);
Expand All @@ -260,7 +263,8 @@ export const MsgAddAuthenticator = {
toAmino(message: MsgAddAuthenticator): MsgAddAuthenticatorAmino {
const obj: any = {};
obj.sender = message.sender === "" ? undefined : message.sender;
obj.type = message.type === "" ? undefined : message.type;
obj.authenticator_type =
message.authenticatorType === "" ? undefined : message.authenticatorType;
obj.data = message.data ? base64FromBytes(message.data) : undefined;
return obj;
},
Expand Down
56 changes: 20 additions & 36 deletions packages/stores/src/account/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
import { queryRPCStatus } from "@osmosis-labs/server";
import {
encodeAnyBase64,
getOsmosisCodec,
QuoteStdFee,
SimulateNotAvailableError,
TxTracer,
Expand Down Expand Up @@ -822,42 +821,27 @@ export class AccountStore<Injects extends Record<string, any>[] = []> {
}
}

const osmosis = await getOsmosisCodec();

/**
* If the message is an authenticator message, force the direct signing.
* This is because the authenticator message should be signed with proto for now.
*/
const isAuthenticatorMsg = messages.some(
(message) =>
message.typeUrl ===
osmosis.smartaccount.v1beta1.MsgAddAuthenticator.typeUrl ||
message.typeUrl ===
osmosis.smartaccount.v1beta1.MsgRemoveAuthenticator.typeUrl
);
if ("signAmino" in offlineSigner || "signAmino" in wallet.client) {
return this.signAmino({
wallet,
signerAddress: wallet.address ?? "",
messages,
fee,
memo,
signerData,
signOptions,
});
}

const forceSignDirect = isAuthenticatorMsg;

return ("signAmino" in offlineSigner || "signAmino" in wallet.client) &&
!forceSignDirect
? this.signAmino({
wallet,
signerAddress: wallet.address ?? "",
messages,
fee,
memo,
signerData,
signOptions,
})
: this.signDirect({
wallet,
signerAddress: wallet.address ?? "",
messages,
fee,
memo,
signerData,
signOptions,
});
return this.signDirect({
wallet,
signerAddress: wallet.address ?? "",
messages,
fee,
memo,
signerData,
signOptions,
});
}

private async signOneClick({
Expand Down
8 changes: 4 additions & 4 deletions packages/stores/src/account/osmosis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ export class OsmosisAccountImpl {
onBroadcasted,
signOptions,
}: {
addAuthenticators: { type: string; data: Uint8Array }[];
addAuthenticators: { authenticatorType: string; data: Uint8Array }[];
removeAuthenticators: bigint[];
memo?: string;
onFulfill?: (tx: DeliverTxResponse) => void;
Expand All @@ -2213,7 +2213,7 @@ export class OsmosisAccountImpl {
}) {
const addAuthenticatorMsgs = addAuthenticators.map((authenticator) =>
makeAddAuthenticatorMsg({
type: authenticator.type,
authenticatorType: authenticator.authenticatorType,
data: authenticator.data,
sender: this.address,
})
Expand Down Expand Up @@ -2262,14 +2262,14 @@ export class OsmosisAccountImpl {
}

async sendAddAuthenticatorsMsg(
authenticators: { type: string; data: any }[],
authenticators: { authenticatorType: string; data: any }[],
memo: string = "",
onFulfill?: (tx: DeliverTxResponse) => void
) {
const addAuthenticatorMsgs = await Promise.all(
authenticators.map((authenticator) =>
makeAddAuthenticatorMsg({
type: authenticator.type,
authenticatorType: authenticator.authenticatorType,
data: authenticator.data,
sender: this.address,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/stores/src/account/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ export const UseOneClickTradingLocalStorageKey = "use-one-click-enabled";
export const HasUsedOneClickTradingLocalStorageKey = "has-used-one-click";

// The number of heights from current before transaction times out.
// 30 heights * 5 second block time = 150 seconds before transaction
// 75 heights * 2 second block time = 150 seconds before transaction
// timeout and mempool eviction.
const defaultTimeoutHeightOffset = 30;
const defaultTimeoutHeightOffset = 75;

export const NEXT_TX_TIMEOUT_HEIGHT_OFFSET: bigint = BigInt(
process.env.TIMEOUT_HEIGHT_OFFSET
Expand Down
6 changes: 3 additions & 3 deletions packages/tx/src/message-composers/osmosis/authenticator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getOsmosisCodec } from "../../codec";

export async function makeAddAuthenticatorMsg({
type,
authenticatorType,
data,
sender,
}: {
type: string;
authenticatorType: string;
data: Uint8Array;
sender: string;
}) {
Expand All @@ -14,7 +14,7 @@ export async function makeAddAuthenticatorMsg({
{
data,
sender,
type,
authenticatorType,
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/transactions/transaction-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface TransactionRow {
value?: PricePretty;
};
onClick?: () => void;
hash: string;
hash?: string;
}

export const TransactionRow: FunctionComponent<TransactionRow> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("isAuthenticatorOneClickTradingSession", () => {
authenticator: {
id: "1",
config: Buffer.from(rawAuthenticator.data).toString("base64"),
type: rawAuthenticator.type,
type: rawAuthenticator.authenticatorType,
},
});
expect(isAuthenticatorOneClickTradingSession({ authenticator })).toBe(true);
Expand Down Expand Up @@ -71,7 +71,7 @@ describe("getOneClickTradingSessionAuthenticator", () => {
sessionPeriod,
});

expect(result.type).toEqual("AllOf");
expect(result.authenticatorType).toEqual("AllOf");
const data = JSON.parse(Buffer.from(result.data).toString());
expect(data).toHaveLength(3);
expect(data[0].type).toEqual("SignatureVerification");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function getOneClickTradingSessionAuthenticator({
allowedAmount: string;
sessionPeriod: OneClickTradingTimeLimit;
}): {
type: AuthenticatorType;
authenticatorType: AuthenticatorType;
data: Uint8Array;
} {
const signatureVerification = {
Expand Down Expand Up @@ -112,8 +112,10 @@ export function getOneClickTradingSessionAuthenticator({
messageFilterAnyOf,
];

// We return the message structure we want to broadcase here,
// not the structure of the authenticator returned from the chain.
return {
type: "AllOf",
authenticatorType: "AllOf",
data: new Uint8Array(
Buffer.from(JSON.stringify(compositeAuthData)).toJSON().data
),
Expand Down

0 comments on commit 958ccdd

Please sign in to comment.