Skip to content

Commit

Permalink
fix: remove stx address check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jul 6, 2022
1 parent 0061735 commit 8bd1a66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/forty-plums-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@stacks/connect': minor
'@stacks/connect-react': minor
---

Removed some logic that breaks JWT signing with Ledger
26 changes: 13 additions & 13 deletions packages/connect/src/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export const getUserSession = (_userSession?: UserSession) => {
return userSession;
};

function hasUserSession(userSession?: UserSession) {
function hasAppPrivateKey(userSession?: UserSession) {
try {
getUserSession(userSession).loadUserData();
return true;
const session = getUserSession(userSession).loadUserData();
return session.appPrivateKey;
} catch (e) {
return false;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ function getDefaults(options: TransactionOptions) {
const network = options.network || new StacksTestnet();

// Legacy auth using localstorage with appPrivateKey
if (hasUserSession(options.userSession)) {
if (hasAppPrivateKey(options.userSession)) {
const userSession = getUserSession(options.userSession);
const defaults: TransactionOptions = {
...options,
Expand All @@ -94,12 +94,12 @@ function getDefaults(options: TransactionOptions) {

// User has not authed, we're relying on the app having previously having been
// given permissions from `stx_requestAccounts`, and the wallet recognising the app's origin
const hasSetRequiredStxAddressPropForRequestAccountFlow = 'stxAddress' in options;
if (!hasSetRequiredStxAddressPropForRequestAccountFlow) {
throw new Error(
'Must set property `stxAddress` when using `stx_requestAccounts to initiate transaction`'
);
}
// const hasSetRequiredStxAddressPropForRequestAccountFlow = 'stxAddress' in options;
// if (!hasSetRequiredStxAddressPropForRequestAccountFlow) {
// throw new Error(
// 'Must set property `stxAddress` when using `stx_requestAccounts to initiate transaction`'
// );
// }
return { ...options, network };
}

Expand Down Expand Up @@ -162,7 +162,7 @@ export const makeContractCallToken = async (options: ContractCallOptions) => {
}
return serializeCV(arg).toString('hex');
});
if (hasUserSession(userSession)) {
if (hasAppPrivateKey(userSession)) {
const { privateKey, publicKey } = getKeys(userSession);
const payload: ContractCallPayload = {
..._options,
Expand All @@ -184,7 +184,7 @@ export const makeContractCallToken = async (options: ContractCallOptions) => {

export const makeContractDeployToken = async (options: ContractDeployOptions) => {
const { appDetails, userSession, ..._options } = options;
if (hasUserSession(userSession)) {
if (hasAppPrivateKey(userSession)) {
const { privateKey, publicKey } = getKeys(userSession);
const payload: ContractDeployPayload = {
..._options,
Expand All @@ -206,7 +206,7 @@ export const makeContractDeployToken = async (options: ContractDeployOptions) =>
export const makeSTXTransferToken = async (options: STXTransferOptions) => {
const { amount, appDetails, userSession, ..._options } = options;

if (hasUserSession(userSession)) {
if (hasAppPrivateKey(userSession)) {
const { privateKey, publicKey } = getKeys(userSession);
const payload: STXTransferPayload = {
..._options,
Expand Down

0 comments on commit 8bd1a66

Please sign in to comment.