Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-worlds-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@turnkey/spark": patch
---

Warn users if they are not using TurnkeySparkSigner with TurnkeySparkWallet
26 changes: 26 additions & 0 deletions packages/spark/src/__tests__/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,32 @@ At the moment, withdrawal requests are leaking test funds into the BTC wallet ${
},
TEST_TIMEOUT,
);

describe("Signer warnings", () => {
let consoleWarnSpy: jest.SpyInstance;

beforeEach(() => {
consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation();
});

afterEach(() => {
consoleWarnSpy.mockRestore();
});

it("should warn if the signer is not a TurnkeySparkSigner", async () => {
await createSparkWallet({} as TurnkeySparkSigner);

expect(consoleWarnSpy).toHaveBeenCalledWith(
"Warning: The provided signer is not a TurnkeySparkSigner.",
);
});

it("should not warn if the signer is a TurnkeySparkSigner", async () => {
await createSparkWallet(senderSigner);

expect(consoleWarnSpy).not.toHaveBeenCalled();
});
});
});

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/spark/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ export class TurnkeySparkSigner implements SparkSigner {
}
}

isTurnkeySparkSigner(): boolean {
return true;
}

// ---------------------------------------------------------------------------
// Identity key operations (already working)
// ---------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions packages/spark/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class TurnkeySparkWallet extends SparkWallet {
constructor(options?: ConfigOptions, signerArg?: SparkSigner) {
super(options, signerArg);

warnIfNotTurnkeySigner(signerArg);

this.transferService = new TurnkeyTransferService(
this.config,
this.connectionManager,
Expand Down Expand Up @@ -127,3 +129,9 @@ export class TurnkeySparkWallet extends SparkWallet {
return (this as any).logging as LoggingService | undefined;
}
}

const warnIfNotTurnkeySigner = (signer: SparkSigner | undefined) => {
if (!(signer as TurnkeySparkSigner)?.isTurnkeySparkSigner?.()) {
console.warn("Warning: The provided signer is not a TurnkeySparkSigner.");
}
};
Loading