Skip to content

Commit

Permalink
fix: make signer optional in getlogicdriver (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvalabs-harshrastogi authored Jan 22, 2024
1 parent 3b938ba commit 6c35691
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 61 deletions.
9 changes: 4 additions & 5 deletions packages/js-moi-logic/dist/logic-base.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { LogicManifest, ManifestCoder } from "js-moi-manifest";
import { IxType } from "js-moi-utils";
import { LogicPayload } from "js-moi-providers";
import { InteractionCallResponse, InteractionResponse, LogicPayload } from "js-moi-providers";
import { Signer } from "js-moi-signer";
import { InteractionResponse, InteractionCallResponse } from "js-moi-providers";
import ElementDescriptor from "./element-descriptor";
import { LogicIxRequest } from "../types/logic";
import { IxType } from "js-moi-utils";
import { LogicIxArguments, LogicIxObject, LogicIxResponse, LogicIxResult } from "../types/interaction";
import { LogicIxRequest } from "../types/logic";
import ElementDescriptor from "./element-descriptor";
/**
* This abstract class extends the ElementDescriptor class and serves as a base
class for logic-related operations.
Expand Down
5 changes: 4 additions & 1 deletion packages/js-moi-logic/dist/logic-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ class LogicBase extends element_descriptor_1.default {
if (args.length < 2) {
js_moi_utils_1.ErrorUtils.throwError("One or more required arguments are missing.", js_moi_utils_1.ErrorCode.MISSING_ARGUMENT);
}
if (args[1].sender == null && this.signer.isInitialized()) {
args[1].sender = this.signer.getAddress();
}
return {
type: args[0],
params: {
sender: this.signer.getAddress(),
sender: args[1].sender,
type: this.getIxType(),
nonce: args[1].nonce,
fuel_price: args[1].fuelPrice,
Expand Down
15 changes: 9 additions & 6 deletions packages/js-moi-logic/src/logic-base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { LogicManifest, ManifestCoder } from "js-moi-manifest";
import { ErrorCode, ErrorUtils, IxType } from "js-moi-utils";
import { LogicPayload } from "js-moi-providers";
import { InteractionCallResponse, InteractionResponse, LogicPayload } from "js-moi-providers";
import { Signer } from "js-moi-signer";
import { InteractionResponse, InteractionCallResponse } from "js-moi-providers";
import ElementDescriptor from "./element-descriptor";
import { LogicIxRequest } from "../types/logic";
import { ErrorCode, ErrorUtils, IxType } from "js-moi-utils";
import { LogicIxArguments, LogicIxObject, LogicIxResponse, LogicIxResult } from "../types/interaction";
import { LogicIxRequest } from "../types/logic";
import ElementDescriptor from "./element-descriptor";

/**
* This abstract class extends the ElementDescriptor class and serves as a base
Expand Down Expand Up @@ -124,11 +123,15 @@ export abstract class LogicBase extends ElementDescriptor {
ErrorCode.MISSING_ARGUMENT
)
}

if(args[1].sender == null && this.signer.isInitialized()) {
args[1].sender = this.signer.getAddress()
}

return {
type: args[0],
params: {
sender: this.signer.getAddress(),
sender: args[1].sender,
type: this.getIxType(),
nonce: args[1].nonce,
fuel_price: args[1].fuelPrice,
Expand Down
6 changes: 2 additions & 4 deletions packages/js-moi-providers/__tests__/jsonrpc-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { Filter, InteractionReceipt } from "../types/jsonrpc";
import { initializeWallet } from "./utils/utils";

describe("Test JsonRpcProvider Query Calls", () => {
const address =
"0x2c1fe83b9d6a5c81c5e6d4da20d2d0509ac3c1eb154e5f5b1fc7d5fd4a03b9cc";
const mnemonic =
"cushion tissue toss meadow glare math custom because inform describe vacant combine";
const address = "0x898ca25ac7a51a36894b9c9f55ec6212500dd8e0c01f6591f0eb9f5b0bc84655";
const mnemonic = "hockey airport rather chef nasty shrimp tragic embrace olive another own hen";
let provider: JsonRpcProvider;
let ixHash: string;
let signer: Signer;
Expand Down
53 changes: 10 additions & 43 deletions packages/js-moi-providers/src/base-provider.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,18 @@
import { LogicManifest } from "js-moi-manifest";
import {
AssetCreationReceipt, AssetMintOrBurnReceipt,
ErrorCode, ErrorUtils,
Interaction,
IxType,
LogicDeployReceipt, LogicInvokeReceipt, Tesseract,
bytesToHex, hexDataLength,
hexToBN,
hexToBytes,
toQuantity,
unmarshal
AssetCreationReceipt, AssetMintOrBurnReceipt, ErrorCode, ErrorUtils, Interaction,
IxType, LogicDeployReceipt, LogicInvokeReceipt, Tesseract, bytesToHex, hexDataLength,
hexToBN, hexToBytes, toQuantity, unmarshal
} from "js-moi-utils";
import { EventType, Listener } from "../types/event";
import {
AccountMetaInfo,
AccountMetaInfoParams,
AccountParamsBase, AccountState,
AccountStateParams,
AssetInfo,
AssetInfoParams, BalanceParams,
CallorEstimateIxObject,
CallorEstimateOptions,
ConnectionsInfo,
Content,
ContentFrom,
ContextInfo,
DBEntryParams,
Encoding,
Filter, FilterDeletionResult,
Inspect,
InteractionByTesseractParams,
InteractionCallResponse,
InteractionParams,
InteractionReceipt,
InteractionRequest,
InteractionResponse,
LogicManifestParams,
NodeInfo,
Options,
Registry,
RpcResponse,
Status,
StorageParams,
SyncStatus, SyncStatusParams,
TDU,
TDUResponse,
TesseractParams
AccountMetaInfo, AccountMetaInfoParams, AccountParamsBase, AccountState, AccountStateParams,
AssetInfo, AssetInfoParams, BalanceParams, CallorEstimateIxObject, CallorEstimateOptions,
ConnectionsInfo, Content, ContentFrom, ContextInfo, DBEntryParams, Encoding, Filter,
FilterDeletionResult, Inspect, InteractionByTesseractParams, InteractionCallResponse,
InteractionParams, InteractionReceipt, InteractionRequest, InteractionResponse,
LogicManifestParams, NodeInfo, Options, Registry, RpcResponse, Status, StorageParams,
SyncStatus, SyncStatusParams, TDU, TDUResponse, TesseractParams
} from "../types/jsonrpc";
import { AbstractProvider } from "./abstract-provider";
import Event from "./event";
Expand Down
1 change: 1 addition & 0 deletions packages/js-moi-signer/dist/signer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export declare abstract class Signer {
abstract getAddress(): string;
abstract connect(provider: AbstractProvider): void;
abstract sign(message: Uint8Array, sigAlgo: SigType): string;
abstract isInitialized(): boolean;
abstract signInteraction(ixObject: InteractionObject, sigAlgo: SigType): InteractionRequest;
/**
* Retrieves the connected provider instance.
Expand Down
5 changes: 4 additions & 1 deletion packages/js-moi-signer/dist/signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ class Signer {
if (!(0, js_moi_utils_1.isValidAddress)(ixObject.sender)) {
js_moi_utils_1.ErrorUtils.throwError("Invalid sender address", js_moi_utils_1.ErrorCode.INVALID_ARGUMENT);
}
if (ixObject.sender !== this.getAddress()) {
if (ixObject.sender == null) {
js_moi_utils_1.ErrorUtils.throwError("Sender address is missing", js_moi_utils_1.ErrorCode.MISSING_ARGUMENT);
}
if (this.isInitialized() && ixObject.sender !== this.getAddress()) {
js_moi_utils_1.ErrorUtils.throwError("Sender address mismatches with the signer", js_moi_utils_1.ErrorCode.UNEXPECTED_ARGUMENT);
}
if (ixObject.type === js_moi_utils_1.IxType.VALUE_TRANSFER) {
Expand Down
7 changes: 6 additions & 1 deletion packages/js-moi-signer/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export abstract class Signer {
abstract getAddress(): string;
abstract connect(provider: AbstractProvider): void;
abstract sign(message: Uint8Array, sigAlgo: SigType): string;
abstract isInitialized(): boolean;
abstract signInteraction(ixObject: InteractionObject, sigAlgo: SigType): InteractionRequest;


Expand Down Expand Up @@ -83,7 +84,11 @@ export abstract class Signer {
ErrorUtils.throwError("Invalid sender address", ErrorCode.INVALID_ARGUMENT);
}

if(ixObject.sender !== this.getAddress()) {
if(ixObject.sender == null) {
ErrorUtils.throwError("Sender address is missing", ErrorCode.MISSING_ARGUMENT);
}

if(this.isInitialized() && ixObject.sender !== this.getAddress()) {
ErrorUtils.throwError("Sender address mismatches with the signer", ErrorCode.UNEXPECTED_ARGUMENT);
}

Expand Down

0 comments on commit 6c35691

Please sign in to comment.