Skip to content

Commit c8d29c4

Browse files
Merge pull request #10 from lazor-kit/feat/enable-direct-execution-transaction
feat: enable direct execution transaction
2 parents 620bd34 + f1875bf commit c8d29c4

File tree

7 files changed

+56
-19
lines changed

7 files changed

+56
-19
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lazorkit/wallet-mobile-adapter",
3-
"version": "1.3.30",
3+
"version": "1.3.74",
44
"main": "dist/index.js",
55
"module": "dist/index.esm.js",
66
"types": "dist/index.d.ts",
@@ -68,7 +68,8 @@
6868
"buffer": "6.0.3",
6969
"expo-web-browser": "^14.2.0",
7070
"js-sha256": "0.11.1",
71+
"react-native": "^0.82.1",
7172
"react-native-get-random-values": "^1.11.0",
7273
"zustand": "^5.0.7"
7374
}
74-
}
75+
}

src/contract/client/lazorkit.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ export class LazorkitClient {
933933
timestamp: BN;
934934
}): Promise<Buffer> {
935935
let message: Buffer;
936-
const { action, smartWallet, passkeyPublicKey, timestamp } = params;
936+
const { action, smartWallet, passkeyPublicKey, credentialHash, timestamp } = params;
937937

938938
switch (action.type) {
939939
case types.SmartWalletAction.Execute: {
@@ -972,15 +972,37 @@ export class LazorkitClient {
972972
action.args as types.ArgsByAction[types.SmartWalletAction.CreateChunk];
973973

974974
const smartWalletConfig = await this.getWalletStateData(smartWallet);
975-
976-
message = buildCreateChunkMessage(
977-
smartWallet,
978-
smartWalletConfig.lastNonce,
979-
timestamp,
980-
policyInstruction,
981-
cpiInstructions,
982-
[...(cpiSigners ?? []), params.payer]
983-
);
975+
if (!policyInstruction) {
976+
const policySigner = this.getWalletDevicePubkey(
977+
smartWallet,
978+
credentialHash
979+
)
980+
const defaultPolicyInstruction = await this.defaultPolicyProgram.buildCheckPolicyIx({
981+
walletId: smartWalletConfig.walletId,
982+
passkeyPublicKey: passkeyPublicKey,
983+
policySigner,
984+
smartWallet,
985+
credentialHash: credentialHash,
986+
policyData: smartWalletConfig.policyData,
987+
});
988+
message = buildCreateChunkMessage(
989+
smartWallet,
990+
smartWalletConfig.lastNonce,
991+
timestamp,
992+
defaultPolicyInstruction,
993+
cpiInstructions,
994+
[...(cpiSigners ?? []), params.payer]
995+
);
996+
} else {
997+
message = buildCreateChunkMessage(
998+
smartWallet,
999+
smartWalletConfig.lastNonce,
1000+
timestamp,
1001+
policyInstruction,
1002+
cpiInstructions,
1003+
[...(cpiSigners ?? []), params.payer]
1004+
);
1005+
}
9841006
break;
9851007
}
9861008
default:

src/contract/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export type ArgsByAction = {
8383
cpiSigners?: readonly anchor.web3.PublicKey[];
8484
};
8585
[SmartWalletAction.CreateChunk]: {
86-
policyInstruction: anchor.web3.TransactionInstruction;
86+
policyInstruction: anchor.web3.TransactionInstruction | null;
8787
cpiInstructions: readonly anchor.web3.TransactionInstruction[];
8888
expiresAt: number;
8989
cpiSigners?: readonly anchor.web3.PublicKey[];

src/core/wallet/actions.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,19 @@ export const createWalletActions = (
179179
timestamp,
180180
credentialHash,
181181
});
182-
return [createChunkTransaction as anchor.web3.VersionedTransaction];
182+
183+
await signAndSendTxn({
184+
base64EncodedTransaction: createChunkTransaction.serialize({ verifySignatures: false, requireAllSignatures: false }).toString('base64'),
185+
relayerUrl: config.paymasterUrl,
186+
});
187+
188+
const executeChunkTransaction = await lazorProgram.executeChunkTxn({
189+
payer: feePayer,
190+
smartWallet: new anchor.web3.PublicKey(data.smartWallet),
191+
cpiInstructions,
192+
});
193+
194+
return [executeChunkTransaction as anchor.web3.VersionedTransaction];
183195
}
184196
default:
185197
throw Error('Execute wallet is error');

src/react/hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as anchor from '@coral-xyz/anchor';
66
import { useWalletStore } from './store';
77
import { ConnectOptions, DisconnectOptions, LazorWalletHook, SignOptions } from '../types';
88
import { logger } from '../core/logger';
9-
import { SmartWalletActionArgs } from '../contract-integration';
9+
import { SmartWalletActionArgs } from '../contract';
1010

1111
export function useLazorWallet(): LazorWalletHook {
1212
const {

src/react/provider.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { logger } from '../core/logger';
99
import { LazorKitProviderProps } from '../types';
1010
import 'react-native-get-random-values';
1111
import { Buffer } from 'buffer';
12-
import { Text } from 'react-native';
1312
import { DEFAULTS } from '../config';
1413

1514
global.Buffer = Buffer;
@@ -69,9 +68,9 @@ export const LazorKitProvider = ({
6968
}, [connection, ipfsUrl, paymasterUrl, rpcUrl, isDebug, setConnection, setConfig]);
7069

7170
try {
72-
return <>{typeof children === 'string' ? <Text>{children}</Text> : children}</>;
71+
return <>{typeof children === 'string' ? <span>{children}</span> : children}</>;
7372
} catch (error) {
7473
logger.error('LazorKitProvider render error:', error);
75-
return <Text>LazorKit Provider Error</Text>;
74+
return <span>LazorKit Provider Error</span>;
7675
}
7776
};

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"esModuleInterop": true,
1111
"resolveJsonModule": true,
1212
"moduleResolution": "node",
13-
"jsx": "react"
13+
"jsx": "react",
14+
"skipLibCheck": true,
15+
"skipDefaultLibCheck": true,
16+
"noEmitOnError": false
1417
},
1518
"include": [
1619
"src"

0 commit comments

Comments
 (0)