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
676 changes: 54 additions & 622 deletions nodes/CrossmintWallets/CrossmintWallets.node.ts

Large diffs are not rendered by default.

109 changes: 109 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@
},
"peerDependencies": {
"n8n-workflow": "*"
},
"dependencies": {
"ethers": "^6.16.0"
}
}
3 changes: 2 additions & 1 deletion shared/actions/checkout/purchaseProduct.operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { API_VERSIONS } from '../../utils/constants';
import { validateRequiredField } from '../../utils/validation';
import { signMessage } from '../../utils/blockchain';
import { TransactionCreateRequest, ApprovalRequest, ApiResponse } from '../../transport/types';
import { ChainFactory } from '../../chains/ChainFactory';

export async function purchaseProduct(
context: IExecuteFunctions,
Expand Down Expand Up @@ -55,7 +56,7 @@ export async function purchaseProduct(
signature,
messageToSign,
signerAddress,
chainType: 'solana',
chainType: ChainFactory.getChainTypeFromNetwork(chain) || 'solana',
chain
};

Expand Down
2 changes: 1 addition & 1 deletion shared/actions/wallet/createWallet.operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function createWallet(

validateRequiredField(externalSignerDetails, 'External signer private key', context, itemIndex);

const keyPair = deriveKeyPair(externalSignerDetails, context, itemIndex);
const keyPair = deriveKeyPair(externalSignerDetails, context, itemIndex, chainType);

const adminSigner = {
type: 'external-wallet',
Expand Down
8 changes: 3 additions & 5 deletions shared/actions/wallet/getBalance.operation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IExecuteFunctions, NodeApiError } from 'n8n-workflow';
import { CrossmintApi } from '../../transport/CrossmintApi';
import { API_VERSIONS } from '../../utils/constants';
import { WalletApi } from '../../api/wallet.api';
import { buildWalletLocator } from '../../utils/locators';
import { WalletLocatorData, ApiResponse } from '../../transport/types';

Expand All @@ -15,13 +15,11 @@ export async function getBalance(
const chainType = context.getNodeParameter('balanceWalletChainType', itemIndex) as string;

const walletLocator = buildWalletLocator(walletResource, chainType, context, itemIndex);

const endpoint = `wallets/${walletLocator}/balances?chains=${encodeURIComponent(chains)}&tokens=${encodeURIComponent(tkn)}`;
const walletApi = new WalletApi(api);

try {
return await api.get(endpoint, API_VERSIONS.WALLETS);
return await walletApi.getBalance(walletLocator, chains, tkn);
} catch (error: unknown) {
// Pass through the original Crossmint API error exactly as received
throw new NodeApiError(context.getNode(), error as object & { message?: string });
}
}
13 changes: 9 additions & 4 deletions shared/actions/wallet/signTransaction.operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { API_VERSIONS, PAGINATION } from '../../utils/constants';
import { validatePrivateKey, validateRequiredField } from '../../utils/validation';
import { signMessage } from '../../utils/blockchain';
import { ApprovalRequest, ApiResponse } from '../../transport/types';
import { ChainFactory } from '../../chains/ChainFactory';

async function getTransactionStatus(
api: CrossmintApi,
Expand Down Expand Up @@ -75,17 +76,21 @@ export async function signTransaction(
api: CrossmintApi,
itemIndex: number,
): Promise<IDataObject> {
const chain = context.getNodeParameter('signSubmitChain', itemIndex) as string;
const chainType = context.getNodeParameter('signSubmitChainType', itemIndex) as string;
// Read the correct network parameter based on chain type
const chain = chainType === 'solana'
? context.getNodeParameter('signSubmitChainSolana', itemIndex) as string
: context.getNodeParameter('signSubmitChainEvm', itemIndex) as string;
Comment on lines +81 to +83
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use chain type constant instead of string literal 'solana' for consistency and type safety

Suggested change
const chain = chainType === 'solana'
? context.getNodeParameter('signSubmitChainSolana', itemIndex) as string
: context.getNodeParameter('signSubmitChainEvm', itemIndex) as string;
const chain = chainType === ChainFactory.getSupportedChainTypes()[0] // 'solana'
? context.getNodeParameter('signSubmitChainSolana', itemIndex) as string
: context.getNodeParameter('signSubmitChainEvm', itemIndex) as string;

Or better yet, consider creating a Chain enum/const object to use here instead of the magic string.

Context Used: Rule from dashboard - Use enum constants (e.g., Chain.SOLANA, Chain.BASE) instead of string literals when comparing chain ... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: shared/actions/wallet/signTransaction.operation.ts
Line: 81:83

Comment:
Use chain type constant instead of string literal `'solana'` for consistency and type safety

```suggestion
	const chain = chainType === ChainFactory.getSupportedChainTypes()[0] // 'solana'
		? context.getNodeParameter('signSubmitChainSolana', itemIndex) as string
		: context.getNodeParameter('signSubmitChainEvm', itemIndex) as string;
```

Or better yet, consider creating a Chain enum/const object to use here instead of the magic string.

**Context Used:** Rule from `dashboard` - Use enum constants (e.g., Chain.SOLANA, Chain.BASE) instead of string literals when comparing chain ... ([source](https://app.greptile.com/review/custom-context?memory=0e60096d-0843-4800-801b-f8a78b766fbc))

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

const privateKey = context.getNodeParameter('signSubmitPrivateKey', itemIndex) as string;
const transactionData = context.getNodeParameter('signSubmitTransactionData', itemIndex) as string;
const walletAddress = context.getNodeParameter('signSubmitWalletAddress', itemIndex) as string;
const transactionId = context.getNodeParameter('signSubmitTransactionId', itemIndex) as string;
const signerAddress = context.getNodeParameter('signSubmitSignerAddress', itemIndex) as string;
const waitForCompletion = context.getNodeParameter('waitForCompletion', itemIndex) as boolean;

validatePrivateKey(privateKey, context, itemIndex);
validatePrivateKey(privateKey, context, itemIndex, chainType);

const signature = await signMessage(transactionData, privateKey, context, itemIndex);
const signature = await signMessage(transactionData, privateKey, context, itemIndex, chainType);

if (!signature) {
throw new NodeOperationError(context.getNode(), 'Failed to generate signature', {
Expand Down Expand Up @@ -127,7 +132,7 @@ export async function signTransaction(
signingDetails: {
signature: signature,
signedTransaction: signature,
chainType: 'solana',
chainType: ChainFactory.getChainTypeFromNetwork(chain) || rawResponseData.chainType || 'solana',
chain: chain,
transactionData: transactionData,
},
Expand Down
16 changes: 16 additions & 0 deletions shared/api/wallet.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { CrossmintApi } from '../transport/CrossmintApi';
import { API_VERSIONS } from '../utils/constants';
import { ApiResponse } from '../transport/types';

export class WalletApi {
constructor(private api: CrossmintApi) {}

async getBalance(
walletLocator: string,
chains: string,
tkn: string,
): Promise<ApiResponse> {
const endpoint = `wallets/${walletLocator}/balances?chains=${encodeURIComponent(chains)}&tokens=${encodeURIComponent(tkn)}`;
return await this.api.get(endpoint, API_VERSIONS.WALLETS);
}
}
Loading