@explorins/pers-sdk-react-native 1.5.3 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/useTransactionSigner.d.ts +1 -0
- package/dist/hooks/useTransactionSigner.d.ts.map +1 -1
- package/dist/hooks/useTransactionSigner.js +28 -5
- package/dist/index.js +28 -5
- package/dist/index.js.map +1 -1
- package/dist/react-native.esm-BtyCg4n1.js +10062 -0
- package/dist/react-native.esm-BtyCg4n1.js.map +1 -0
- package/package.json +1 -1
- package/src/hooks/useTransactionSigner.ts +45 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTransactionSigner.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactionSigner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTransactionSigner.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactionSigner.ts"],"names":[],"mappings":"AA6EA,UAAU,wBAAwB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,oBAAoB;IA0K7B;;OAEG;2BAtE2C,MAAM,KAAG,QAAQ,wBAAwB,CAAC;IAyExF;;OAEG;gCAvIgD;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B;IAsIC;;OAEG;;IAGH;;OAEG;;CAGN,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAE5E;;GAEG;AACH,YAAY,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -76,27 +76,34 @@ export const useTransactionSigner = () => {
|
|
|
76
76
|
const signerSDKRef = useRef(null);
|
|
77
77
|
// Auto-initialize signer when user is authenticated and real SDK is available
|
|
78
78
|
useEffect(() => {
|
|
79
|
-
if (isInitialized && isAuthenticated && user && !isSignerInitialized) {
|
|
79
|
+
if (isInitialized && isAuthenticated && user && !isSignerInitialized && sdk) {
|
|
80
80
|
console.log('[useTransactionSigner] Auto-initializing PERS transaction signer...');
|
|
81
|
+
// Get configuration from the PERS SDK
|
|
82
|
+
const sdkConfig = sdk.config || {};
|
|
83
|
+
const apiProjectKey = sdkConfig.apiProjectKey || 'demo-project-key';
|
|
84
|
+
const tenantId = sdkConfig.tenantId || 'vq-demo';
|
|
81
85
|
initializeSigner({
|
|
82
|
-
tenantId:
|
|
86
|
+
tenantId: tenantId,
|
|
87
|
+
projectKey: apiProjectKey,
|
|
83
88
|
ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
|
|
84
89
|
}).catch((error) => {
|
|
85
90
|
console.error('[useTransactionSigner] Auto-initialization failed:', error);
|
|
86
91
|
});
|
|
87
92
|
}
|
|
88
|
-
}, [isInitialized, isAuthenticated, user, isSignerInitialized,
|
|
93
|
+
}, [isInitialized, isAuthenticated, user, isSignerInitialized, sdk]);
|
|
89
94
|
/**
|
|
90
95
|
* Initialize the blockchain signer with configuration
|
|
91
96
|
*
|
|
92
97
|
* @param config - Signer configuration options
|
|
93
98
|
* @param config.tenantId - Multi-tenant identifier for the signer
|
|
99
|
+
* @param config.projectKey - PERS project API key for authentication
|
|
94
100
|
* @param config.ethersProviderUrl - Custom blockchain provider URL
|
|
95
101
|
*
|
|
96
102
|
* @example
|
|
97
103
|
* ```typescript
|
|
98
104
|
* await initializeSigner({
|
|
99
105
|
* tenantId: 'my-tenant-id',
|
|
106
|
+
* projectKey: 'your-pers-api-key',
|
|
100
107
|
* ethersProviderUrl: 'https://sepolia.infura.io/v3/your-key'
|
|
101
108
|
* });
|
|
102
109
|
* ```
|
|
@@ -107,6 +114,16 @@ export const useTransactionSigner = () => {
|
|
|
107
114
|
}
|
|
108
115
|
try {
|
|
109
116
|
console.log('[useTransactionSigner] Initializing PERS transaction signer...');
|
|
117
|
+
// Configure the PERS service with the project key before creating SDK
|
|
118
|
+
if (config?.projectKey) {
|
|
119
|
+
console.log('[useTransactionSigner] Configuring PERS service with project key:', config.projectKey);
|
|
120
|
+
// Import and configure the PERS service
|
|
121
|
+
const { PersService } = await import('@explorins/pers-signer/react-native');
|
|
122
|
+
PersService.configure({
|
|
123
|
+
projectKey: config.projectKey
|
|
124
|
+
});
|
|
125
|
+
console.log('[useTransactionSigner] PERS service configured with project key');
|
|
126
|
+
}
|
|
110
127
|
const signerSDK = await createPersSignerSDK({
|
|
111
128
|
tenantId: config?.tenantId,
|
|
112
129
|
ethersProviderUrl: config?.ethersProviderUrl || DEFAULT_ETHERS_PROVIDER
|
|
@@ -166,9 +183,15 @@ export const useTransactionSigner = () => {
|
|
|
166
183
|
email: currentUser.email || jwtUserInfo.email,
|
|
167
184
|
id: currentUser.id || jwtUserInfo.userId
|
|
168
185
|
};
|
|
169
|
-
//
|
|
186
|
+
// Get PERS access token from the main SDK
|
|
187
|
+
const authProvider = sdk.authProvider || sdk._authProvider;
|
|
188
|
+
const persAccessToken = authProvider ? await authProvider.getToken() : '';
|
|
189
|
+
// Authenticate user with blockchain signer and pass PERS token
|
|
170
190
|
console.log('[useTransactionSigner] Authenticating user with signer:', signerUserInfo.identifier);
|
|
171
|
-
const signerUser = await signerSDKRef.current.authenticateUser(
|
|
191
|
+
const signerUser = await signerSDKRef.current.authenticateUser({
|
|
192
|
+
...signerUserInfo,
|
|
193
|
+
persAccessToken: persAccessToken
|
|
194
|
+
});
|
|
172
195
|
// Sign the PERS transaction using JWT
|
|
173
196
|
console.log('[useTransactionSigner] Signing PERS transaction with JWT containing transaction data');
|
|
174
197
|
const result = await signerSDKRef.current.signPersTransaction(signerUser, jwt);
|
package/dist/index.js
CHANGED
|
@@ -30318,27 +30318,34 @@ const useTransactionSigner = () => {
|
|
|
30318
30318
|
const signerSDKRef = react.useRef(null);
|
|
30319
30319
|
// Auto-initialize signer when user is authenticated and real SDK is available
|
|
30320
30320
|
react.useEffect(() => {
|
|
30321
|
-
if (isInitialized && isAuthenticated && user && !isSignerInitialized) {
|
|
30321
|
+
if (isInitialized && isAuthenticated && user && !isSignerInitialized && sdk) {
|
|
30322
30322
|
console.log('[useTransactionSigner] Auto-initializing PERS transaction signer...');
|
|
30323
|
+
// Get configuration from the PERS SDK
|
|
30324
|
+
const sdkConfig = sdk.config || {};
|
|
30325
|
+
const apiProjectKey = sdkConfig.apiProjectKey || 'demo-project-key';
|
|
30326
|
+
const tenantId = sdkConfig.tenantId || 'vq-demo';
|
|
30323
30327
|
initializeSigner({
|
|
30324
|
-
tenantId:
|
|
30328
|
+
tenantId: tenantId,
|
|
30329
|
+
projectKey: apiProjectKey,
|
|
30325
30330
|
ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
|
|
30326
30331
|
}).catch((error) => {
|
|
30327
30332
|
console.error('[useTransactionSigner] Auto-initialization failed:', error);
|
|
30328
30333
|
});
|
|
30329
30334
|
}
|
|
30330
|
-
}, [isInitialized, isAuthenticated, user, isSignerInitialized,
|
|
30335
|
+
}, [isInitialized, isAuthenticated, user, isSignerInitialized, sdk]);
|
|
30331
30336
|
/**
|
|
30332
30337
|
* Initialize the blockchain signer with configuration
|
|
30333
30338
|
*
|
|
30334
30339
|
* @param config - Signer configuration options
|
|
30335
30340
|
* @param config.tenantId - Multi-tenant identifier for the signer
|
|
30341
|
+
* @param config.projectKey - PERS project API key for authentication
|
|
30336
30342
|
* @param config.ethersProviderUrl - Custom blockchain provider URL
|
|
30337
30343
|
*
|
|
30338
30344
|
* @example
|
|
30339
30345
|
* ```typescript
|
|
30340
30346
|
* await initializeSigner({
|
|
30341
30347
|
* tenantId: 'my-tenant-id',
|
|
30348
|
+
* projectKey: 'your-pers-api-key',
|
|
30342
30349
|
* ethersProviderUrl: 'https://sepolia.infura.io/v3/your-key'
|
|
30343
30350
|
* });
|
|
30344
30351
|
* ```
|
|
@@ -30349,6 +30356,16 @@ const useTransactionSigner = () => {
|
|
|
30349
30356
|
}
|
|
30350
30357
|
try {
|
|
30351
30358
|
console.log('[useTransactionSigner] Initializing PERS transaction signer...');
|
|
30359
|
+
// Configure the PERS service with the project key before creating SDK
|
|
30360
|
+
if (config?.projectKey) {
|
|
30361
|
+
console.log('[useTransactionSigner] Configuring PERS service with project key:', config.projectKey);
|
|
30362
|
+
// Import and configure the PERS service
|
|
30363
|
+
const { PersService } = await Promise.resolve().then(function () { return require('./react-native.esm-BtyCg4n1.js'); });
|
|
30364
|
+
PersService.configure({
|
|
30365
|
+
projectKey: config.projectKey
|
|
30366
|
+
});
|
|
30367
|
+
console.log('[useTransactionSigner] PERS service configured with project key');
|
|
30368
|
+
}
|
|
30352
30369
|
const signerSDK = await createPersSignerSDK({
|
|
30353
30370
|
tenantId: config?.tenantId,
|
|
30354
30371
|
ethersProviderUrl: config?.ethersProviderUrl || DEFAULT_ETHERS_PROVIDER
|
|
@@ -30408,9 +30425,15 @@ const useTransactionSigner = () => {
|
|
|
30408
30425
|
email: currentUser.email || jwtUserInfo.email,
|
|
30409
30426
|
id: currentUser.id || jwtUserInfo.userId
|
|
30410
30427
|
};
|
|
30411
|
-
//
|
|
30428
|
+
// Get PERS access token from the main SDK
|
|
30429
|
+
const authProvider = sdk.authProvider || sdk._authProvider;
|
|
30430
|
+
const persAccessToken = authProvider ? await authProvider.getToken() : '';
|
|
30431
|
+
// Authenticate user with blockchain signer and pass PERS token
|
|
30412
30432
|
console.log('[useTransactionSigner] Authenticating user with signer:', signerUserInfo.identifier);
|
|
30413
|
-
const signerUser = await signerSDKRef.current.authenticateUser(
|
|
30433
|
+
const signerUser = await signerSDKRef.current.authenticateUser({
|
|
30434
|
+
...signerUserInfo,
|
|
30435
|
+
persAccessToken: persAccessToken
|
|
30436
|
+
});
|
|
30414
30437
|
// Sign the PERS transaction using JWT
|
|
30415
30438
|
console.log('[useTransactionSigner] Signing PERS transaction with JWT containing transaction data');
|
|
30416
30439
|
const result = await signerSDKRef.current.signPersTransaction(signerUser, jwt);
|