@mocanetwork/airkit 0.5.0-beta.2 → 0.5.0
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/airkit.cjs.js +119 -7
- package/dist/airkit.esm.js +119 -7
- package/dist/airkit.umd.min.js +1 -1
- package/dist/lib.cjs/common/src/realm/messaging/types.js +7 -1
- package/dist/lib.cjs/ws-embed/src/airService.js +37 -3
- package/dist/lib.cjs/ws-embed/src/embed.js +15 -0
- package/dist/lib.cjs/ws-embed/src/messageService.js +58 -1
- package/dist/lib.cjs/ws-embed/src/utils.js +2 -2
- package/dist/lib.esm/common/src/realm/messaging/types.js +7 -1
- package/dist/lib.esm/ws-embed/src/airService.js +37 -3
- package/dist/lib.esm/ws-embed/src/embed.js +15 -0
- package/dist/lib.esm/ws-embed/src/messageService.js +58 -1
- package/dist/lib.esm/ws-embed/src/utils.js +2 -2
- package/dist/types/airService.d.ts +25 -0
- package/dist/types/common/realm/messaging/types.d.ts +50 -2
- package/dist/types/common/realm/partner/config.d.ts +28 -26
- package/dist/types/common/realm/smart-session/hex.d.ts +1 -0
- package/dist/types/common/realm/smart-session/rule.d.ts +49 -0
- package/dist/types/common/realm/smart-session/types.d.ts +56 -0
- package/dist/types/common/realm/user/types.d.ts +1 -1
- package/dist/types/embed.d.ts +13 -0
- package/dist/types/interfaces.d.ts +4 -3
- package/dist/types/messageService.d.ts +13 -0
- package/package.json +1 -1
|
@@ -9,7 +9,13 @@ const AirMessageTypes = {
|
|
|
9
9
|
CLOSE_MODAL: "air_close_modal",
|
|
10
10
|
INIT_AUTH_COMMUNICATION: "air_init_auth_communication",
|
|
11
11
|
DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request",
|
|
12
|
-
DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response"
|
|
12
|
+
DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response",
|
|
13
|
+
GRANT_PERMISSIONS_REQUEST: "air_grant_permissions_request",
|
|
14
|
+
GRANT_PERMISSIONS_RESPONSE: "air_grant_permissions_response",
|
|
15
|
+
EXECUTE_ACTION_REQUEST: "air_execute_action_request",
|
|
16
|
+
EXECUTE_ACTION_RESPONSE: "air_execute_action_response",
|
|
17
|
+
REVOKE_PERMISSIONS_REQUEST: "air_revoke_permissions_request",
|
|
18
|
+
REVOKE_PERMISSIONS_RESPONSE: "air_revoke_permissions_response"
|
|
13
19
|
};
|
|
14
20
|
|
|
15
21
|
exports.AirMessageTypes = AirMessageTypes;
|
|
@@ -126,7 +126,9 @@ class AirService {
|
|
|
126
126
|
const authServiceInitialization = messageService.waitForAuthInitialization();
|
|
127
127
|
const result = await Promise.all([initializationPromise, authServiceInitialization]);
|
|
128
128
|
_classPrivateFieldSet(_isInitialized, this, true);
|
|
129
|
-
_assertClassBrand(_AirService_brand, this, _triggerAirAuthInitialized).call(this
|
|
129
|
+
_assertClassBrand(_AirService_brand, this, _triggerAirAuthInitialized).call(this, {
|
|
130
|
+
rehydrated: result[1].rehydrated
|
|
131
|
+
});
|
|
130
132
|
_assertClassBrand(_AirService_brand, this, _prepareRealmEmbedListeners).call(this);
|
|
131
133
|
|
|
132
134
|
// rehydrated auth session
|
|
@@ -178,11 +180,42 @@ class AirService {
|
|
|
178
180
|
}
|
|
179
181
|
throw new error.AirServiceError("UNKNOWN_ERROR", "Unknown error occurred");
|
|
180
182
|
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @experimental This method is experimental and will change in the future.
|
|
186
|
+
*/
|
|
181
187
|
async deploySmartAccount() {
|
|
182
188
|
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("Service is not initialized");
|
|
183
189
|
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
184
190
|
return _classPrivateFieldGet(_realmEmbed, this)._deploySmartAccount();
|
|
185
191
|
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @experimental This method is experimental and will change in the future.
|
|
195
|
+
*/
|
|
196
|
+
async grantPermission(policies) {
|
|
197
|
+
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
198
|
+
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
199
|
+
return _classPrivateFieldGet(_realmEmbed, this)._grantPermission(policies);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @experimental This method is experimental and will change in the future.
|
|
204
|
+
*/
|
|
205
|
+
async executeAction(params) {
|
|
206
|
+
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
207
|
+
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
208
|
+
return _classPrivateFieldGet(_realmEmbed, this)._executeAction(params);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @experimental This method is experimental and will change in the future.
|
|
213
|
+
*/
|
|
214
|
+
async revokePermission(permissionId) {
|
|
215
|
+
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
216
|
+
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
217
|
+
return _classPrivateFieldGet(_realmEmbed, this)._revokePermission(permissionId);
|
|
218
|
+
}
|
|
186
219
|
async logout() {
|
|
187
220
|
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("Service is not initialized");
|
|
188
221
|
if (!this.isLoggedIn) throw new Error("No active session to logout");
|
|
@@ -310,9 +343,10 @@ async function _triggerEventListeners(data) {
|
|
|
310
343
|
listener(data);
|
|
311
344
|
});
|
|
312
345
|
}
|
|
313
|
-
async function _triggerAirAuthInitialized() {
|
|
346
|
+
async function _triggerAirAuthInitialized(result) {
|
|
314
347
|
await _assertClassBrand(_AirService_brand, this, _triggerEventListeners).call(this, {
|
|
315
|
-
event: "initialized"
|
|
348
|
+
event: "initialized",
|
|
349
|
+
result
|
|
316
350
|
});
|
|
317
351
|
}
|
|
318
352
|
async function _triggerAirAuthLoggedIn() {
|
|
@@ -334,6 +334,21 @@ class RealmEmbed {
|
|
|
334
334
|
throw error.RealmEmbedError.from(error$1);
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
|
+
async _grantPermission(policies) {
|
|
338
|
+
if (!this.isConnected) throw new error.RealmEmbedError("NOT_LOGGED_IN", "User needs to be connected first");
|
|
339
|
+
try {
|
|
340
|
+
return await messageService.sendGrantPermissionRequest(_classPrivateFieldGet(_walletIframe, this), policies);
|
|
341
|
+
} catch (error$1) {
|
|
342
|
+
throw error.RealmEmbedError.from(error$1);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
async _executeAction(params) {
|
|
346
|
+
return messageService.sendExecuteActionRequest(_classPrivateFieldGet(_walletIframe, this), params);
|
|
347
|
+
}
|
|
348
|
+
async _revokePermission(permissionId) {
|
|
349
|
+
return messageService.sendRevokePermissionsRequest(_classPrivateFieldGet(_walletIframe, this), permissionId);
|
|
350
|
+
}
|
|
351
|
+
|
|
337
352
|
// async loginV2<T extends boolean>(options?: {
|
|
338
353
|
// skipClaiming: T;
|
|
339
354
|
// token?: string;
|
|
@@ -8,7 +8,7 @@ var types = require('../../common/src/realm/messaging/types.js');
|
|
|
8
8
|
var error = require('./error.js');
|
|
9
9
|
var loglevel = require('./loglevel.js');
|
|
10
10
|
|
|
11
|
-
const REALM_EMBED_MESSAGES = [types.AirMessageTypes.LOGIN_CLAIM_STATE, types.AirMessageTypes.CLOSE_MODAL, types.AirMessageTypes.SERVICE_INITIALIZED, types.AirMessageTypes.SERVICE_INITIALIZED_ERROR, types.AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE];
|
|
11
|
+
const REALM_EMBED_MESSAGES = [types.AirMessageTypes.LOGIN_CLAIM_STATE, types.AirMessageTypes.CLOSE_MODAL, types.AirMessageTypes.SERVICE_INITIALIZED, types.AirMessageTypes.SERVICE_INITIALIZED_ERROR, types.AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE, types.AirMessageTypes.EXECUTE_ACTION_RESPONSE, types.AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE, types.AirMessageTypes.GRANT_PERMISSIONS_RESPONSE];
|
|
12
12
|
const AUTH_EMBED_MESSAGES = [auth.AirAuthMessageTypes.LOGIN_RESPONSE, auth.AirAuthMessageTypes.USER_INFO_RESPONSE, auth.AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE, auth.AirAuthMessageTypes.REFRESH_TOKEN_RESPONSE, auth.AirAuthMessageTypes.INITIALIZATION_RESPONSE, auth.AirAuthMessageTypes.LOGOUT_RESPONSE, auth.AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST, auth.AirAuthMessageTypes.SETUP_WALLET_REQUEST];
|
|
13
13
|
class AirMessageService {
|
|
14
14
|
constructor() {
|
|
@@ -125,6 +125,63 @@ class AirMessageService {
|
|
|
125
125
|
}, origin);
|
|
126
126
|
return response;
|
|
127
127
|
}
|
|
128
|
+
async sendGrantPermissionRequest(walletIframe, policies) {
|
|
129
|
+
const response = rxjs.firstValueFrom(this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.GRANT_PERMISSIONS_RESPONSE)));
|
|
130
|
+
const {
|
|
131
|
+
origin
|
|
132
|
+
} = new URL(walletIframe.src);
|
|
133
|
+
walletIframe.contentWindow.postMessage({
|
|
134
|
+
type: types.AirMessageTypes.GRANT_PERMISSIONS_REQUEST,
|
|
135
|
+
payload: {
|
|
136
|
+
policies
|
|
137
|
+
}
|
|
138
|
+
}, origin);
|
|
139
|
+
const result = await response;
|
|
140
|
+
if (result.payload.success === false) {
|
|
141
|
+
throw new error.RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
142
|
+
}
|
|
143
|
+
return result.payload.sessionData;
|
|
144
|
+
}
|
|
145
|
+
async sendExecuteActionRequest(walletIframe, params) {
|
|
146
|
+
const response = rxjs.firstValueFrom(this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.EXECUTE_ACTION_RESPONSE)));
|
|
147
|
+
const {
|
|
148
|
+
origin
|
|
149
|
+
} = new URL(walletIframe.src);
|
|
150
|
+
walletIframe.contentWindow.postMessage({
|
|
151
|
+
type: types.AirMessageTypes.EXECUTE_ACTION_REQUEST,
|
|
152
|
+
payload: {
|
|
153
|
+
sessionData: params.sessionData,
|
|
154
|
+
call: {
|
|
155
|
+
to: params.call.to,
|
|
156
|
+
value: params.call.value,
|
|
157
|
+
data: params.call.data
|
|
158
|
+
},
|
|
159
|
+
sessionOwnerPrivateKey: params.sessionOwnerPrivateKey
|
|
160
|
+
}
|
|
161
|
+
}, origin);
|
|
162
|
+
const result = await response;
|
|
163
|
+
if (result.payload.success === false) {
|
|
164
|
+
throw new error.RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
165
|
+
}
|
|
166
|
+
return result.payload.txHash;
|
|
167
|
+
}
|
|
168
|
+
async sendRevokePermissionsRequest(walletIframe, permissionId) {
|
|
169
|
+
const response = rxjs.firstValueFrom(this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE)));
|
|
170
|
+
const {
|
|
171
|
+
origin
|
|
172
|
+
} = new URL(walletIframe.src);
|
|
173
|
+
walletIframe.contentWindow.postMessage({
|
|
174
|
+
type: types.AirMessageTypes.REVOKE_PERMISSIONS_REQUEST,
|
|
175
|
+
payload: {
|
|
176
|
+
permissionId
|
|
177
|
+
}
|
|
178
|
+
}, origin);
|
|
179
|
+
const result = await response;
|
|
180
|
+
if (result.payload.success === false) {
|
|
181
|
+
throw new error.RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
182
|
+
}
|
|
183
|
+
return result.payload.txHash;
|
|
184
|
+
}
|
|
128
185
|
sendDeploySmartAccountRequest(walletIframe) {
|
|
129
186
|
const response = rxjs.firstValueFrom(this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE)));
|
|
130
187
|
const {
|
|
@@ -17,12 +17,12 @@ const AIR_URLS = {
|
|
|
17
17
|
logLevel: "debug"
|
|
18
18
|
},
|
|
19
19
|
[interfaces.EMBED_BUILD_ENV.STAGING]: {
|
|
20
|
-
authUrl: "https://
|
|
20
|
+
authUrl: "https://auth.staging.air3.com",
|
|
21
21
|
walletUrl: "https://account.staging.realmnetwork.io",
|
|
22
22
|
logLevel: "info"
|
|
23
23
|
},
|
|
24
24
|
[interfaces.EMBED_BUILD_ENV.PRODUCTION]: {
|
|
25
|
-
authUrl: "https://
|
|
25
|
+
authUrl: "https://auth.air3.com",
|
|
26
26
|
walletUrl: "https://account.realmnetwork.io",
|
|
27
27
|
logLevel: "error"
|
|
28
28
|
}
|
|
@@ -7,7 +7,13 @@ const AirMessageTypes = {
|
|
|
7
7
|
CLOSE_MODAL: "air_close_modal",
|
|
8
8
|
INIT_AUTH_COMMUNICATION: "air_init_auth_communication",
|
|
9
9
|
DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request",
|
|
10
|
-
DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response"
|
|
10
|
+
DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response",
|
|
11
|
+
GRANT_PERMISSIONS_REQUEST: "air_grant_permissions_request",
|
|
12
|
+
GRANT_PERMISSIONS_RESPONSE: "air_grant_permissions_response",
|
|
13
|
+
EXECUTE_ACTION_REQUEST: "air_execute_action_request",
|
|
14
|
+
EXECUTE_ACTION_RESPONSE: "air_execute_action_response",
|
|
15
|
+
REVOKE_PERMISSIONS_REQUEST: "air_revoke_permissions_request",
|
|
16
|
+
REVOKE_PERMISSIONS_RESPONSE: "air_revoke_permissions_response"
|
|
11
17
|
};
|
|
12
18
|
|
|
13
19
|
export { AirMessageTypes };
|
|
@@ -124,7 +124,9 @@ class AirService {
|
|
|
124
124
|
const authServiceInitialization = AirMessageService.waitForAuthInitialization();
|
|
125
125
|
const result = await Promise.all([initializationPromise, authServiceInitialization]);
|
|
126
126
|
_classPrivateFieldSet(_isInitialized, this, true);
|
|
127
|
-
_assertClassBrand(_AirService_brand, this, _triggerAirAuthInitialized).call(this
|
|
127
|
+
_assertClassBrand(_AirService_brand, this, _triggerAirAuthInitialized).call(this, {
|
|
128
|
+
rehydrated: result[1].rehydrated
|
|
129
|
+
});
|
|
128
130
|
_assertClassBrand(_AirService_brand, this, _prepareRealmEmbedListeners).call(this);
|
|
129
131
|
|
|
130
132
|
// rehydrated auth session
|
|
@@ -176,11 +178,42 @@ class AirService {
|
|
|
176
178
|
}
|
|
177
179
|
throw new AirServiceError("UNKNOWN_ERROR", "Unknown error occurred");
|
|
178
180
|
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @experimental This method is experimental and will change in the future.
|
|
184
|
+
*/
|
|
179
185
|
async deploySmartAccount() {
|
|
180
186
|
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("Service is not initialized");
|
|
181
187
|
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
182
188
|
return _classPrivateFieldGet(_realmEmbed, this)._deploySmartAccount();
|
|
183
189
|
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @experimental This method is experimental and will change in the future.
|
|
193
|
+
*/
|
|
194
|
+
async grantPermission(policies) {
|
|
195
|
+
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
196
|
+
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
197
|
+
return _classPrivateFieldGet(_realmEmbed, this)._grantPermission(policies);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @experimental This method is experimental and will change in the future.
|
|
202
|
+
*/
|
|
203
|
+
async executeAction(params) {
|
|
204
|
+
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
205
|
+
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
206
|
+
return _classPrivateFieldGet(_realmEmbed, this)._executeAction(params);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @experimental This method is experimental and will change in the future.
|
|
211
|
+
*/
|
|
212
|
+
async revokePermission(permissionId) {
|
|
213
|
+
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("AirAuth is not initialized");
|
|
214
|
+
await _assertClassBrand(_AirService_brand, this, _ensureWallet).call(this);
|
|
215
|
+
return _classPrivateFieldGet(_realmEmbed, this)._revokePermission(permissionId);
|
|
216
|
+
}
|
|
184
217
|
async logout() {
|
|
185
218
|
if (!_classPrivateFieldGet(_isInitialized, this)) throw new Error("Service is not initialized");
|
|
186
219
|
if (!this.isLoggedIn) throw new Error("No active session to logout");
|
|
@@ -308,9 +341,10 @@ async function _triggerEventListeners(data) {
|
|
|
308
341
|
listener(data);
|
|
309
342
|
});
|
|
310
343
|
}
|
|
311
|
-
async function _triggerAirAuthInitialized() {
|
|
344
|
+
async function _triggerAirAuthInitialized(result) {
|
|
312
345
|
await _assertClassBrand(_AirService_brand, this, _triggerEventListeners).call(this, {
|
|
313
|
-
event: "initialized"
|
|
346
|
+
event: "initialized",
|
|
347
|
+
result
|
|
314
348
|
});
|
|
315
349
|
}
|
|
316
350
|
async function _triggerAirAuthLoggedIn() {
|
|
@@ -330,6 +330,21 @@ class RealmEmbed {
|
|
|
330
330
|
throw RealmEmbedError.from(error);
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
+
async _grantPermission(policies) {
|
|
334
|
+
if (!this.isConnected) throw new RealmEmbedError("NOT_LOGGED_IN", "User needs to be connected first");
|
|
335
|
+
try {
|
|
336
|
+
return await AirMessageService.sendGrantPermissionRequest(_classPrivateFieldGet(_walletIframe, this), policies);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
throw RealmEmbedError.from(error);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
async _executeAction(params) {
|
|
342
|
+
return AirMessageService.sendExecuteActionRequest(_classPrivateFieldGet(_walletIframe, this), params);
|
|
343
|
+
}
|
|
344
|
+
async _revokePermission(permissionId) {
|
|
345
|
+
return AirMessageService.sendRevokePermissionsRequest(_classPrivateFieldGet(_walletIframe, this), permissionId);
|
|
346
|
+
}
|
|
347
|
+
|
|
333
348
|
// async loginV2<T extends boolean>(options?: {
|
|
334
349
|
// skipClaiming: T;
|
|
335
350
|
// token?: string;
|
|
@@ -6,7 +6,7 @@ import { AirMessageTypes } from '../../common/src/realm/messaging/types.js';
|
|
|
6
6
|
import { RealmEmbedError } from './error.js';
|
|
7
7
|
import log from './loglevel.js';
|
|
8
8
|
|
|
9
|
-
const REALM_EMBED_MESSAGES = [AirMessageTypes.LOGIN_CLAIM_STATE, AirMessageTypes.CLOSE_MODAL, AirMessageTypes.SERVICE_INITIALIZED, AirMessageTypes.SERVICE_INITIALIZED_ERROR, AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE];
|
|
9
|
+
const REALM_EMBED_MESSAGES = [AirMessageTypes.LOGIN_CLAIM_STATE, AirMessageTypes.CLOSE_MODAL, AirMessageTypes.SERVICE_INITIALIZED, AirMessageTypes.SERVICE_INITIALIZED_ERROR, AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE, AirMessageTypes.EXECUTE_ACTION_RESPONSE, AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE, AirMessageTypes.GRANT_PERMISSIONS_RESPONSE];
|
|
10
10
|
const AUTH_EMBED_MESSAGES = [AirAuthMessageTypes.LOGIN_RESPONSE, AirAuthMessageTypes.USER_INFO_RESPONSE, AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE, AirAuthMessageTypes.REFRESH_TOKEN_RESPONSE, AirAuthMessageTypes.INITIALIZATION_RESPONSE, AirAuthMessageTypes.LOGOUT_RESPONSE, AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST, AirAuthMessageTypes.SETUP_WALLET_REQUEST];
|
|
11
11
|
class AirMessageService {
|
|
12
12
|
constructor() {
|
|
@@ -123,6 +123,63 @@ class AirMessageService {
|
|
|
123
123
|
}, origin);
|
|
124
124
|
return response;
|
|
125
125
|
}
|
|
126
|
+
async sendGrantPermissionRequest(walletIframe, policies) {
|
|
127
|
+
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirMessageTypes.GRANT_PERMISSIONS_RESPONSE)));
|
|
128
|
+
const {
|
|
129
|
+
origin
|
|
130
|
+
} = new URL(walletIframe.src);
|
|
131
|
+
walletIframe.contentWindow.postMessage({
|
|
132
|
+
type: AirMessageTypes.GRANT_PERMISSIONS_REQUEST,
|
|
133
|
+
payload: {
|
|
134
|
+
policies
|
|
135
|
+
}
|
|
136
|
+
}, origin);
|
|
137
|
+
const result = await response;
|
|
138
|
+
if (result.payload.success === false) {
|
|
139
|
+
throw new RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
140
|
+
}
|
|
141
|
+
return result.payload.sessionData;
|
|
142
|
+
}
|
|
143
|
+
async sendExecuteActionRequest(walletIframe, params) {
|
|
144
|
+
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirMessageTypes.EXECUTE_ACTION_RESPONSE)));
|
|
145
|
+
const {
|
|
146
|
+
origin
|
|
147
|
+
} = new URL(walletIframe.src);
|
|
148
|
+
walletIframe.contentWindow.postMessage({
|
|
149
|
+
type: AirMessageTypes.EXECUTE_ACTION_REQUEST,
|
|
150
|
+
payload: {
|
|
151
|
+
sessionData: params.sessionData,
|
|
152
|
+
call: {
|
|
153
|
+
to: params.call.to,
|
|
154
|
+
value: params.call.value,
|
|
155
|
+
data: params.call.data
|
|
156
|
+
},
|
|
157
|
+
sessionOwnerPrivateKey: params.sessionOwnerPrivateKey
|
|
158
|
+
}
|
|
159
|
+
}, origin);
|
|
160
|
+
const result = await response;
|
|
161
|
+
if (result.payload.success === false) {
|
|
162
|
+
throw new RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
163
|
+
}
|
|
164
|
+
return result.payload.txHash;
|
|
165
|
+
}
|
|
166
|
+
async sendRevokePermissionsRequest(walletIframe, permissionId) {
|
|
167
|
+
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE)));
|
|
168
|
+
const {
|
|
169
|
+
origin
|
|
170
|
+
} = new URL(walletIframe.src);
|
|
171
|
+
walletIframe.contentWindow.postMessage({
|
|
172
|
+
type: AirMessageTypes.REVOKE_PERMISSIONS_REQUEST,
|
|
173
|
+
payload: {
|
|
174
|
+
permissionId
|
|
175
|
+
}
|
|
176
|
+
}, origin);
|
|
177
|
+
const result = await response;
|
|
178
|
+
if (result.payload.success === false) {
|
|
179
|
+
throw new RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
180
|
+
}
|
|
181
|
+
return result.payload.txHash;
|
|
182
|
+
}
|
|
126
183
|
sendDeploySmartAccountRequest(walletIframe) {
|
|
127
184
|
const response = firstValueFrom(this.messages$.pipe(filter(msg => msg.type === AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE)));
|
|
128
185
|
const {
|
|
@@ -15,12 +15,12 @@ const AIR_URLS = {
|
|
|
15
15
|
logLevel: "debug"
|
|
16
16
|
},
|
|
17
17
|
[EMBED_BUILD_ENV.STAGING]: {
|
|
18
|
-
authUrl: "https://
|
|
18
|
+
authUrl: "https://auth.staging.air3.com",
|
|
19
19
|
walletUrl: "https://account.staging.realmnetwork.io",
|
|
20
20
|
logLevel: "info"
|
|
21
21
|
},
|
|
22
22
|
[EMBED_BUILD_ENV.PRODUCTION]: {
|
|
23
|
-
authUrl: "https://
|
|
23
|
+
authUrl: "https://auth.air3.com",
|
|
24
24
|
walletUrl: "https://account.realmnetwork.io",
|
|
25
25
|
logLevel: "error"
|
|
26
26
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Hex } from "./common/realm/smart-session/hex";
|
|
2
|
+
import { ActionPolicyInfo, Call } from "./common/realm/smart-session/types";
|
|
1
3
|
import AirInPageProvider from "./inPageProvider";
|
|
2
4
|
import { AirEmbedConnectResult, AirEmbedLoginResult, AirEventListener, AirLoginResult, AirPartnerUserDetails, AirUserDetails, ClaimAirIdOptions, EMBED_BUILD_ENV_TYPE } from "./interfaces";
|
|
3
5
|
declare class AirService {
|
|
@@ -19,7 +21,30 @@ declare class AirService {
|
|
|
19
21
|
login(options?: {
|
|
20
22
|
authToken?: string;
|
|
21
23
|
}): Promise<AirLoginResult>;
|
|
24
|
+
/**
|
|
25
|
+
* @experimental This method is experimental and will change in the future.
|
|
26
|
+
*/
|
|
22
27
|
deploySmartAccount(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* @experimental This method is experimental and will change in the future.
|
|
30
|
+
*/
|
|
31
|
+
grantPermission(policies: ActionPolicyInfo[]): Promise<{
|
|
32
|
+
compressedSessionData: string;
|
|
33
|
+
sessionOwnerPrivateKey: string;
|
|
34
|
+
permissionIds: string[];
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* @experimental This method is experimental and will change in the future.
|
|
38
|
+
*/
|
|
39
|
+
executeAction(params: {
|
|
40
|
+
sessionData: string;
|
|
41
|
+
call: Call;
|
|
42
|
+
sessionOwnerPrivateKey: `0x${string}`;
|
|
43
|
+
}): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* @experimental This method is experimental and will change in the future.
|
|
46
|
+
*/
|
|
47
|
+
revokePermission(permissionId: Hex): Promise<string>;
|
|
23
48
|
logout(): Promise<void>;
|
|
24
49
|
getProvider(): Promise<AirInPageProvider>;
|
|
25
50
|
preloadWallet(): Promise<AirEmbedConnectResult | AirEmbedLoginResult>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Hex } from "viem";
|
|
1
2
|
import { AirErrorName } from "../error/types";
|
|
3
|
+
import { ActionPolicyInfo, Call } from "../smart-session/types";
|
|
2
4
|
export declare const AirMessageTypes: {
|
|
3
5
|
readonly SERVICE_INITIALIZED: "air_service_initialized";
|
|
4
6
|
readonly SERVICE_INITIALIZED_ERROR: "air_service_initialized_error";
|
|
@@ -9,6 +11,12 @@ export declare const AirMessageTypes: {
|
|
|
9
11
|
readonly INIT_AUTH_COMMUNICATION: "air_init_auth_communication";
|
|
10
12
|
readonly DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request";
|
|
11
13
|
readonly DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response";
|
|
14
|
+
readonly GRANT_PERMISSIONS_REQUEST: "air_grant_permissions_request";
|
|
15
|
+
readonly GRANT_PERMISSIONS_RESPONSE: "air_grant_permissions_response";
|
|
16
|
+
readonly EXECUTE_ACTION_REQUEST: "air_execute_action_request";
|
|
17
|
+
readonly EXECUTE_ACTION_RESPONSE: "air_execute_action_response";
|
|
18
|
+
readonly REVOKE_PERMISSIONS_REQUEST: "air_revoke_permissions_request";
|
|
19
|
+
readonly REVOKE_PERMISSIONS_RESPONSE: "air_revoke_permissions_response";
|
|
12
20
|
};
|
|
13
21
|
export declare const AirLoginClaimStates: {
|
|
14
22
|
readonly CONNECTED: "connected";
|
|
@@ -88,8 +96,48 @@ export type AirDeploySmartAccountResponseMessage = AirMessageBase<"air_deploy_sm
|
|
|
88
96
|
txHash: string;
|
|
89
97
|
} | {
|
|
90
98
|
success: false;
|
|
91
|
-
|
|
99
|
+
errorName: AirErrorName;
|
|
100
|
+
errorMessage?: string;
|
|
101
|
+
}>;
|
|
102
|
+
export type AirGrantPermissionsRequestMessage = AirMessageBase<"air_grant_permissions_request", {
|
|
103
|
+
policies: ActionPolicyInfo[];
|
|
104
|
+
}>;
|
|
105
|
+
export type AirGrantPermissionsResponseMessage = AirMessageBase<"air_grant_permissions_response", {
|
|
106
|
+
success: true;
|
|
107
|
+
sessionData: {
|
|
108
|
+
compressedSessionData: string;
|
|
109
|
+
sessionOwnerPrivateKey: string;
|
|
110
|
+
permissionIds: string[];
|
|
111
|
+
};
|
|
112
|
+
} | {
|
|
113
|
+
success: false;
|
|
114
|
+
errorName: AirErrorName;
|
|
115
|
+
errorMessage?: string;
|
|
116
|
+
}>;
|
|
117
|
+
export type AirExecuteActionRequestMessage = AirMessageBase<"air_execute_action_request", {
|
|
118
|
+
sessionData: string;
|
|
119
|
+
call: Call;
|
|
120
|
+
sessionOwnerPrivateKey: `0x${string}`;
|
|
121
|
+
}>;
|
|
122
|
+
export type AirRevokePermissionsRequestMessage = AirMessageBase<"air_revoke_permissions_request", {
|
|
123
|
+
permissionId: Hex;
|
|
124
|
+
}>;
|
|
125
|
+
export type AirRevokePermissionsResponseMessage = AirMessageBase<"air_revoke_permissions_response", {
|
|
126
|
+
success: true;
|
|
127
|
+
txHash: string;
|
|
128
|
+
} | {
|
|
129
|
+
success: false;
|
|
130
|
+
errorName: AirErrorName;
|
|
131
|
+
errorMessage?: string;
|
|
132
|
+
}>;
|
|
133
|
+
export type AirExecuteActionResponseMessage = AirMessageBase<"air_execute_action_response", {
|
|
134
|
+
success: true;
|
|
135
|
+
txHash: string;
|
|
136
|
+
} | {
|
|
137
|
+
success: false;
|
|
138
|
+
errorName: AirErrorName;
|
|
139
|
+
errorMessage?: string;
|
|
92
140
|
}>;
|
|
93
|
-
export type AirMessage = AirServiceInitializedMessage | AirServiceInitializedErrorMessage | AirLoginRequestMessage | AirClaimRequestMessage | AirLoginClaimStateMessage | AirCloseModalMessage | AirInitAuthCommunicationMessage | AirDeploySmartAccountRequestMessage | AirDeploySmartAccountResponseMessage;
|
|
141
|
+
export type AirMessage = AirServiceInitializedMessage | AirServiceInitializedErrorMessage | AirLoginRequestMessage | AirClaimRequestMessage | AirLoginClaimStateMessage | AirCloseModalMessage | AirInitAuthCommunicationMessage | AirDeploySmartAccountRequestMessage | AirDeploySmartAccountResponseMessage | AirGrantPermissionsRequestMessage | AirGrantPermissionsResponseMessage | AirRevokePermissionsRequestMessage | AirRevokePermissionsResponseMessage | AirExecuteActionRequestMessage | AirExecuteActionResponseMessage;
|
|
94
142
|
export type AirLoginClaimStatePayload = AirLoginClaimStateMessage["payload"];
|
|
95
143
|
export {};
|
|
@@ -1,30 +1,4 @@
|
|
|
1
1
|
import { RealmLoginWalletId } from "../wallet";
|
|
2
|
-
export type RealmPartnerConfig = {
|
|
3
|
-
partnerId: string;
|
|
4
|
-
node: string;
|
|
5
|
-
gating: "none" | "jwt" | "invite";
|
|
6
|
-
apiUrl: string;
|
|
7
|
-
theme?: string;
|
|
8
|
-
chainId: string;
|
|
9
|
-
allowedDomains?: string[];
|
|
10
|
-
publicKey?: string;
|
|
11
|
-
jwksUrl?: string;
|
|
12
|
-
realmIdValidation: RealmIdValidation;
|
|
13
|
-
allowConnectOnly: boolean;
|
|
14
|
-
cyberConnectAppId?: string;
|
|
15
|
-
style?: RealmPartnerConfigStyle;
|
|
16
|
-
walletLoginMethods?: RealmLoginWalletId[];
|
|
17
|
-
walletSignupMethods?: RealmLoginWalletId[];
|
|
18
|
-
recommendedWallets?: RealmLoginWalletId[];
|
|
19
|
-
defaultLanguage?: string;
|
|
20
|
-
supportedLocales?: string[];
|
|
21
|
-
localeUrls?: Record<string, string>;
|
|
22
|
-
authLocaleUrls?: Record<string, string>;
|
|
23
|
-
sessionTime?: number;
|
|
24
|
-
customAuth?: RealmCustomAuthConfig;
|
|
25
|
-
allowSessionIdLogin?: boolean;
|
|
26
|
-
loginMethods?: RealmLoginMethod[];
|
|
27
|
-
};
|
|
28
2
|
export type RealmIdValidation = {
|
|
29
3
|
minLength: number;
|
|
30
4
|
maxLength: number;
|
|
@@ -32,6 +6,7 @@ export type RealmIdValidation = {
|
|
|
32
6
|
export type RealmPartnerConfigStyle = {
|
|
33
7
|
hideCloseIcon?: boolean;
|
|
34
8
|
hideModalOverlay?: boolean;
|
|
9
|
+
passwordlessButtonVariant?: "inline" | "standalone";
|
|
35
10
|
};
|
|
36
11
|
export declare const REALM_LOGIN_PROVIDER: {
|
|
37
12
|
readonly REALM_CUSTOM_AUTH: "realm_custom_auth";
|
|
@@ -66,3 +41,30 @@ export type RealmCustomAuthConfig = {
|
|
|
66
41
|
};
|
|
67
42
|
export declare const REALM_LOGIN_METHODS: readonly ["passwordless", "passwordlessToggle", "google", "wallet", "passkey"];
|
|
68
43
|
export type RealmLoginMethod = (typeof REALM_LOGIN_METHODS)[number];
|
|
44
|
+
export type RealmPartnerConfig = {
|
|
45
|
+
partnerId: string;
|
|
46
|
+
node: string;
|
|
47
|
+
gating: "none" | "jwt" | "invite";
|
|
48
|
+
apiUrl: string;
|
|
49
|
+
theme?: string;
|
|
50
|
+
chainId: string;
|
|
51
|
+
allowedDomains?: string[];
|
|
52
|
+
publicKey?: string;
|
|
53
|
+
jwksUrl?: string;
|
|
54
|
+
realmIdValidation: RealmIdValidation;
|
|
55
|
+
allowConnectOnly: boolean;
|
|
56
|
+
cyberConnectAppId?: string;
|
|
57
|
+
style?: RealmPartnerConfigStyle;
|
|
58
|
+
walletLoginMethods?: RealmLoginWalletId[];
|
|
59
|
+
walletSignupMethods?: RealmLoginWalletId[];
|
|
60
|
+
recommendedWallets?: RealmLoginWalletId[];
|
|
61
|
+
defaultLanguage?: string;
|
|
62
|
+
supportedLocales?: string[];
|
|
63
|
+
localeUrls?: Record<string, string>;
|
|
64
|
+
authLocaleUrls?: Record<string, string>;
|
|
65
|
+
sessionTime?: number;
|
|
66
|
+
customAuth?: RealmCustomAuthConfig;
|
|
67
|
+
allowSessionIdLogin?: boolean;
|
|
68
|
+
loginMethods?: RealmLoginMethod[];
|
|
69
|
+
skipPartnerLinkingConfirmation?: boolean;
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Hex = `0x${string}`;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Hex } from "./hex";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the usage limit for a rule.
|
|
4
|
+
*/
|
|
5
|
+
export type LimitUsage = {
|
|
6
|
+
limit: bigint;
|
|
7
|
+
used: bigint;
|
|
8
|
+
};
|
|
9
|
+
export type ByteArray = Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Represents a hardcoded hex value reference.
|
|
12
|
+
* Used when you want to bypass automatic hex conversion.
|
|
13
|
+
*/
|
|
14
|
+
export type HardcodedReference = {
|
|
15
|
+
/** The raw hex value */
|
|
16
|
+
raw: Hex;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Base types that can be converted to hex references.
|
|
20
|
+
*/
|
|
21
|
+
type BaseReferenceValue = string | number | bigint | boolean | ByteArray;
|
|
22
|
+
export type AnyReferenceValue = BaseReferenceValue | HardcodedReference;
|
|
23
|
+
/**
|
|
24
|
+
* Enum representing different parameter conditions for rules.
|
|
25
|
+
*/
|
|
26
|
+
export declare enum ParamCondition {
|
|
27
|
+
EQUAL = 0,
|
|
28
|
+
GREATER_THAN = 1,
|
|
29
|
+
LESS_THAN = 2,
|
|
30
|
+
GREATER_THAN_OR_EQUAL = 3,
|
|
31
|
+
LESS_THAN_OR_EQUAL = 4,
|
|
32
|
+
NOT_EQUAL = 5
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents a rule for action policies.
|
|
36
|
+
*/
|
|
37
|
+
export type Rule = {
|
|
38
|
+
/** The condition to apply to the parameter */
|
|
39
|
+
condition: ParamCondition;
|
|
40
|
+
/** The offset index in the calldata where the value to be checked is located */
|
|
41
|
+
offsetIndex: number;
|
|
42
|
+
/** Indicates if the rule has a usage limit */
|
|
43
|
+
isLimited: boolean;
|
|
44
|
+
/** The reference value to compare against */
|
|
45
|
+
ref: AnyReferenceValue;
|
|
46
|
+
/** The usage object containing limit and used values (required if isLimited is true) */
|
|
47
|
+
usage: LimitUsage;
|
|
48
|
+
};
|
|
49
|
+
export {};
|