@imtbl/sdk 0.1.7-alpha.1 → 0.1.7-alpha.3

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/passport.js CHANGED
@@ -1,5 +1,3 @@
1
- import * as guardian from '@imtbl/guardian';
2
- export { guardian };
3
1
  import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner } from '@imtbl/core-sdk';
4
2
  import { UserManager } from 'oidc-client-ts';
5
3
  import { ethers } from 'ethers';
@@ -15,24 +13,33 @@ var Environment;
15
13
  })(Environment || (Environment = {}));
16
14
 
17
15
  /**
18
- * Set `sdkVersion` on config
16
+ * createImmutableXConfiguration to create a custom ImmutableXConfiguration
17
+ * other than the production and sandbox defined below.
19
18
  */
20
- const production = () => Config.createConfig({
19
+ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress, registrationContractAddress, }) => Config.createConfig({
20
+ basePath,
21
+ chainID,
22
+ coreContractAddress,
23
+ registrationContractAddress,
24
+ sdkVersion: 'ts-immutable-sdk-0.1.7-alpha.3',
25
+ });
26
+ /**
27
+ * Sets `sdkVersion` at the time of build
28
+ */
29
+ const production = () => createImmutableXConfiguration({
21
30
  basePath: 'https://api.x.immutable.com',
22
31
  chainID: 1,
23
32
  coreContractAddress: '0x5FDCCA53617f4d2b9134B29090C87D01058e27e9',
24
33
  registrationContractAddress: '0x72a06bf2a1CE5e39cBA06c0CAb824960B587d64c',
25
- sdkVersion: 'ts-immutable-sdk-0.1.7-alpha.1',
26
34
  });
27
35
  /**
28
- * Set `sdkVersion` on config
36
+ * Sets `sdkVersion` at the time of build
29
37
  */
30
- const sandbox = () => Config.createConfig({
38
+ const sandbox = () => createImmutableXConfiguration({
31
39
  basePath: 'https://api.sandbox.x.immutable.com',
32
40
  chainID: 5,
33
41
  coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
34
42
  registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
35
- sdkVersion: 'ts-immutable-sdk-0.1.7-alpha.1',
36
43
  });
37
44
  class ImxConfiguration {
38
45
  immutableXConfig;
@@ -772,25 +779,13 @@ var SendMessage;
772
779
  })(SendMessage || (SendMessage = {}));
773
780
  var TransactionTypes;
774
781
  (function (TransactionTypes) {
775
- // TODO: remove this once the naming has been fixed
776
- // eslint-disable-next-line @typescript-eslint/naming-convention
777
- TransactionTypes["CancelOrder"] = "delete:v1/orders";
778
- // TODO: remove this once the naming has been fixed
779
- // eslint-disable-next-line @typescript-eslint/naming-convention
780
- TransactionTypes["CreateOrder"] = "post:v1/orders";
781
- // TODO: remove this once the naming has been fixed
782
- // eslint-disable-next-line @typescript-eslint/naming-convention
783
- TransactionTypes["CreateTrade"] = "post:v1/trades";
784
- // TODO: remove this once the naming has been fixed
785
- // eslint-disable-next-line @typescript-eslint/naming-convention
786
- TransactionTypes["CreateTransfer"] = "post:v1/transfers";
787
- // TODO: remove this once the naming has been fixed
788
- // eslint-disable-next-line @typescript-eslint/naming-convention
789
- TransactionTypes["CreateBatchTransfer"] = "post:v2/transfers";
782
+ TransactionTypes["cancelOrder"] = "delete:v1/orders";
783
+ TransactionTypes["createOrder"] = "post:v1/orders";
784
+ TransactionTypes["createTrade"] = "post:v1/trades";
785
+ TransactionTypes["createTransfer"] = "post:v1/transfers";
786
+ TransactionTypes["createBatchTransfer"] = "post:v2/transfers";
790
787
  })(TransactionTypes || (TransactionTypes = {}));
791
- // TODO: remove this once the naming has been fixed
792
- // eslint-disable-next-line @typescript-eslint/naming-convention
793
- const PassportEventType = 'imx_passport_confirmation';
788
+ const PASSPORT_EVENT_TYPE = 'imx_passport_confirmation';
794
789
 
795
790
  const openPopupCenter = ({ url, title, width, height, }) => {
796
791
  const left = Math.max(0, Math.round(window.screenX + (window.outerWidth - width) / 2));
@@ -820,7 +815,7 @@ class ConfirmationScreen {
820
815
  }
821
816
  postMessage(destinationWindow, accessToken, message) {
822
817
  destinationWindow.postMessage({
823
- eventType: PassportEventType,
818
+ eventType: PASSPORT_EVENT_TYPE,
824
819
  accessToken,
825
820
  ...message,
826
821
  }, this.config.passportDomain);
@@ -829,7 +824,7 @@ class ConfirmationScreen {
829
824
  return new Promise((resolve, reject) => {
830
825
  const messageHandler = ({ data, origin }) => {
831
826
  if (origin !== this.config.passportDomain
832
- || data.eventType !== PassportEventType) {
827
+ || data.eventType !== PASSPORT_EVENT_TYPE) {
833
828
  return;
834
829
  }
835
830
  switch (data.messageType) {
@@ -874,59 +869,57 @@ class ConfirmationScreen {
874
869
  }
875
870
 
876
871
  const ERC721$1 = 'ERC721';
877
- const transfer = ({ request, transfersApi, starkSigner, user, passportConfig,
878
- // TODO: remove this eslint disable once we have a better solution
879
- // eslint-disable-next-line max-len
880
- }) => withPassportError(async () => {
881
- const transferAmount = request.type === ERC721$1 ? '1' : request.amount;
882
- const getSignableTransferRequest = {
883
- sender: user.etherKey,
884
- token: convertToSignableToken(request),
885
- amount: transferAmount,
886
- receiver: request.receiver,
887
- };
888
- const signableResult = await transfersApi.getSignableTransferV1({
889
- getSignableTransferRequest,
890
- });
891
- const confirmationScreen = new ConfirmationScreen(passportConfig);
892
- const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
893
- transactionType: TransactionTypes.CreateTransfer,
894
- transactionData: getSignableTransferRequest,
895
- });
896
- if (!confirmationResult.confirmed) {
897
- throw new Error('Transaction rejected by user');
898
- }
899
- const signableResultData = signableResult.data;
900
- const { payload_hash: payloadHash } = signableResultData;
901
- const starkSignature = await starkSigner.signMessage(payloadHash);
902
- const senderStarkKey = await starkSigner.getAddress();
903
- const transferSigningParams = {
904
- sender_stark_key: signableResultData.sender_stark_key || senderStarkKey,
905
- sender_vault_id: signableResultData.sender_vault_id,
906
- receiver_stark_key: signableResultData.receiver_stark_key,
907
- receiver_vault_id: signableResultData.receiver_vault_id,
908
- asset_id: signableResultData.asset_id,
909
- amount: signableResultData.amount,
910
- nonce: signableResultData.nonce,
911
- expiration_timestamp: signableResultData.expiration_timestamp,
912
- stark_signature: starkSignature,
913
- };
914
- const createTransferRequest = {
915
- createTransferRequest: transferSigningParams,
916
- };
917
- const headers = {
918
- // eslint-disable-next-line @typescript-eslint/naming-convention
919
- Authorization: `Bearer ${user.accessToken}`,
920
- };
921
- const { data: responseData } = await transfersApi.createTransferV1(createTransferRequest, { headers });
922
- return {
923
- sent_signature: responseData.sent_signature,
924
- status: responseData.status?.toString(),
925
- time: responseData.time,
926
- transfer_id: responseData.transfer_id,
927
- };
928
- }, PassportErrorType.TRANSFER_ERROR);
929
- async function batchNftTransfer({ user, starkSigner, request, transfersApi, passportConfig, }) {
872
+ async function transfer({ request, transfersApi, starkSigner, user, confirmationScreen, }) {
873
+ return withPassportError(async () => {
874
+ const transferAmount = request.type === ERC721$1 ? '1' : request.amount;
875
+ const getSignableTransferRequest = {
876
+ sender: user.etherKey,
877
+ token: convertToSignableToken(request),
878
+ amount: transferAmount,
879
+ receiver: request.receiver,
880
+ };
881
+ const signableResult = await transfersApi.getSignableTransferV1({
882
+ getSignableTransferRequest,
883
+ });
884
+ const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
885
+ transactionType: TransactionTypes.createTransfer,
886
+ transactionData: getSignableTransferRequest,
887
+ });
888
+ if (!confirmationResult.confirmed) {
889
+ throw new Error('Transaction rejected by user');
890
+ }
891
+ const signableResultData = signableResult.data;
892
+ const { payload_hash: payloadHash } = signableResultData;
893
+ const starkSignature = await starkSigner.signMessage(payloadHash);
894
+ const senderStarkKey = await starkSigner.getAddress();
895
+ const transferSigningParams = {
896
+ sender_stark_key: signableResultData.sender_stark_key || senderStarkKey,
897
+ sender_vault_id: signableResultData.sender_vault_id,
898
+ receiver_stark_key: signableResultData.receiver_stark_key,
899
+ receiver_vault_id: signableResultData.receiver_vault_id,
900
+ asset_id: signableResultData.asset_id,
901
+ amount: signableResultData.amount,
902
+ nonce: signableResultData.nonce,
903
+ expiration_timestamp: signableResultData.expiration_timestamp,
904
+ stark_signature: starkSignature,
905
+ };
906
+ const createTransferRequest = {
907
+ createTransferRequest: transferSigningParams,
908
+ };
909
+ const headers = {
910
+ // eslint-disable-next-line @typescript-eslint/naming-convention
911
+ Authorization: `Bearer ${user.accessToken}`,
912
+ };
913
+ const { data: responseData } = await transfersApi.createTransferV1(createTransferRequest, { headers });
914
+ return {
915
+ sent_signature: responseData.sent_signature,
916
+ status: responseData.status?.toString(),
917
+ time: responseData.time,
918
+ transfer_id: responseData.transfer_id,
919
+ };
920
+ }, PassportErrorType.TRANSFER_ERROR);
921
+ }
922
+ async function batchNftTransfer({ user, starkSigner, request, transfersApi, confirmationScreen, }) {
930
923
  return withPassportError(async () => {
931
924
  const ethAddress = user.etherKey;
932
925
  const signableRequests = request.map((nftTransfer) => ({
@@ -945,10 +938,9 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, pass
945
938
  const signableResult = await transfersApi.getSignableTransfer({
946
939
  getSignableTransferRequestV2,
947
940
  });
948
- const confirmationScreen = new ConfirmationScreen(passportConfig);
949
941
  const popupWindowSize = { width: 480, height: 784 };
950
942
  const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
951
- transactionType: TransactionTypes.CreateBatchTransfer,
943
+ transactionType: TransactionTypes.createBatchTransfer,
952
944
  transactionData: getSignableTransferRequestV2,
953
945
  }, popupWindowSize);
954
946
  if (!confirmationResult.confirmed) {
@@ -985,7 +977,7 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, pass
985
977
  }
986
978
 
987
979
  const ERC721 = 'ERC721';
988
- async function createOrder({ starkSigner, user, request, ordersApi, passportConfig, }) {
980
+ async function createOrder({ starkSigner, user, request, ordersApi, confirmationScreen, }) {
989
981
  return withPassportError(async () => {
990
982
  const ethAddress = user.etherKey;
991
983
  const amountSell = request.sell.type === ERC721 ? '1' : request.sell.amount;
@@ -1002,9 +994,8 @@ async function createOrder({ starkSigner, user, request, ordersApi, passportConf
1002
994
  const getSignableOrderResponse = await ordersApi.getSignableOrder({
1003
995
  getSignableOrderRequestV3,
1004
996
  });
1005
- const confirmationScreen = new ConfirmationScreen(passportConfig);
1006
997
  const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
1007
- transactionType: TransactionTypes.CreateOrder,
998
+ transactionType: TransactionTypes.createOrder,
1008
999
  transactionData: getSignableOrderRequestV3,
1009
1000
  });
1010
1001
  if (!confirmationResult.confirmed) {
@@ -1041,7 +1032,7 @@ async function createOrder({ starkSigner, user, request, ordersApi, passportConf
1041
1032
  };
1042
1033
  }, PassportErrorType.CREATE_ORDER_ERROR);
1043
1034
  }
1044
- async function cancelOrder({ user, starkSigner, request, ordersApi, passportConfig, }) {
1035
+ async function cancelOrder({ user, starkSigner, request, ordersApi, confirmationScreen, }) {
1045
1036
  return withPassportError(async () => {
1046
1037
  const getSignableCancelOrderRequest = {
1047
1038
  order_id: request.order_id,
@@ -1049,9 +1040,8 @@ async function cancelOrder({ user, starkSigner, request, ordersApi, passportConf
1049
1040
  const getSignableCancelOrderResponse = await ordersApi.getSignableCancelOrder({
1050
1041
  getSignableCancelOrderRequest,
1051
1042
  });
1052
- const confirmationScreen = new ConfirmationScreen(passportConfig);
1053
1043
  const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
1054
- transactionType: TransactionTypes.CancelOrder,
1044
+ transactionType: TransactionTypes.cancelOrder,
1055
1045
  transactionData: getSignableCancelOrderRequest,
1056
1046
  });
1057
1047
  if (!confirmationResult.confirmed) {
@@ -1121,7 +1111,7 @@ async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
1121
1111
  }, PassportErrorType.EXCHANGE_TRANSFER_ERROR);
1122
1112
  }
1123
1113
 
1124
- async function createTrade({ request, tradesApi, user, starkSigner, passportConfig, }) {
1114
+ async function createTrade({ request, tradesApi, user, starkSigner, confirmationScreen, }) {
1125
1115
  return withPassportError(async () => {
1126
1116
  const ethAddress = user.etherKey;
1127
1117
  const getSignableTradeRequest = {
@@ -1133,9 +1123,8 @@ async function createTrade({ request, tradesApi, user, starkSigner, passportConf
1133
1123
  const getSignableTradeResponse = await tradesApi.getSignableTrade({
1134
1124
  getSignableTradeRequest,
1135
1125
  });
1136
- const confirmationScreen = new ConfirmationScreen(passportConfig);
1137
1126
  const confirmationResult = await confirmationScreen.startTransaction(user.accessToken, {
1138
- transactionType: TransactionTypes.CreateTrade,
1127
+ transactionType: TransactionTypes.createTrade,
1139
1128
  transactionData: getSignableTradeRequest,
1140
1129
  });
1141
1130
  if (!confirmationResult.confirmed) {
@@ -1174,13 +1163,13 @@ async function createTrade({ request, tradesApi, user, starkSigner, passportConf
1174
1163
  class PassportImxProvider {
1175
1164
  user;
1176
1165
  starkSigner;
1177
- passportConfig;
1178
1166
  immutableXClient;
1179
- constructor({ user, starkSigner, passportConfig, immutableXClient, }) {
1167
+ confirmationScreen;
1168
+ constructor({ user, starkSigner, immutableXClient, confirmationScreen, }) {
1180
1169
  this.user = user;
1181
1170
  this.starkSigner = starkSigner;
1182
- this.passportConfig = passportConfig;
1183
1171
  this.immutableXClient = immutableXClient;
1172
+ this.confirmationScreen = confirmationScreen;
1184
1173
  }
1185
1174
  async transfer(request) {
1186
1175
  return transfer({
@@ -1188,7 +1177,7 @@ class PassportImxProvider {
1188
1177
  user: this.user,
1189
1178
  starkSigner: this.starkSigner,
1190
1179
  transfersApi: this.immutableXClient.transfersApi,
1191
- passportConfig: this.passportConfig,
1180
+ confirmationScreen: this.confirmationScreen,
1192
1181
  });
1193
1182
  }
1194
1183
  // TODO: Remove once implemented
@@ -1207,7 +1196,7 @@ class PassportImxProvider {
1207
1196
  user: this.user,
1208
1197
  starkSigner: this.starkSigner,
1209
1198
  ordersApi: this.immutableXClient.ordersApi,
1210
- passportConfig: this.passportConfig,
1199
+ confirmationScreen: this.confirmationScreen,
1211
1200
  });
1212
1201
  }
1213
1202
  cancelOrder(request) {
@@ -1216,7 +1205,7 @@ class PassportImxProvider {
1216
1205
  user: this.user,
1217
1206
  starkSigner: this.starkSigner,
1218
1207
  ordersApi: this.immutableXClient.ordersApi,
1219
- passportConfig: this.passportConfig,
1208
+ confirmationScreen: this.confirmationScreen,
1220
1209
  });
1221
1210
  }
1222
1211
  createTrade(request) {
@@ -1225,7 +1214,7 @@ class PassportImxProvider {
1225
1214
  user: this.user,
1226
1215
  starkSigner: this.starkSigner,
1227
1216
  tradesApi: this.immutableXClient.tradesApi,
1228
- passportConfig: this.passportConfig,
1217
+ confirmationScreen: this.confirmationScreen,
1229
1218
  });
1230
1219
  }
1231
1220
  batchNftTransfer(request) {
@@ -1234,7 +1223,7 @@ class PassportImxProvider {
1234
1223
  user: this.user,
1235
1224
  starkSigner: this.starkSigner,
1236
1225
  transfersApi: this.immutableXClient.transfersApi,
1237
- passportConfig: this.passportConfig,
1226
+ confirmationScreen: this.confirmationScreen,
1238
1227
  });
1239
1228
  }
1240
1229
  exchangeTransfer(request) {
@@ -1374,17 +1363,17 @@ async function registerPassport({ ethSigner, starkSigner, usersApi }, authorizat
1374
1363
  }, PassportErrorType.USER_REGISTRATION_ERROR);
1375
1364
  }
1376
1365
 
1377
- // TODO: Remove this once the dependency has been added
1378
- // eslint-disable-next-line import/no-extraneous-dependencies
1379
1366
  class Passport {
1380
1367
  authManager;
1381
1368
  magicAdapter;
1382
1369
  config;
1383
1370
  immutableXClient;
1371
+ confirmationScreen;
1384
1372
  constructor(passportModuleConfiguration) {
1385
1373
  this.config = new PassportConfiguration(passportModuleConfiguration);
1386
1374
  this.authManager = new AuthManager(this.config);
1387
1375
  this.magicAdapter = new MagicAdapter(this.config);
1376
+ this.confirmationScreen = new ConfirmationScreen(this.config);
1388
1377
  this.immutableXClient = passportModuleConfiguration.overrides?.immutableXClient
1389
1378
  || new ImmutableXClient({
1390
1379
  baseConfig: passportModuleConfiguration.baseConfig,
@@ -1402,16 +1391,16 @@ class Passport {
1402
1391
  return new PassportImxProvider({
1403
1392
  user: updatedUser,
1404
1393
  starkSigner,
1405
- passportConfig: this.config,
1406
1394
  immutableXClient: this.immutableXClient,
1395
+ confirmationScreen: this.confirmationScreen,
1407
1396
  });
1408
1397
  }
1409
1398
  const userWithEtherKey = user;
1410
1399
  return new PassportImxProvider({
1411
1400
  user: userWithEtherKey,
1412
1401
  starkSigner,
1413
- passportConfig: this.config,
1414
1402
  immutableXClient: this.immutableXClient,
1403
+ confirmationScreen: this.confirmationScreen,
1415
1404
  });
1416
1405
  }
1417
1406
  async connectImxSilent() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.1.7-alpha.1",
4
+ "version": "0.1.7-alpha.3",
5
5
  "author": "Immutable",
6
6
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
7
7
  "dependencies": {
@@ -20,10 +20,14 @@
20
20
  "oidc-client-ts": "^2.2.1"
21
21
  },
22
22
  "devDependencies": {
23
+ "@imtbl/blockchain-data": "0.0.0",
23
24
  "@imtbl/checkout-sdk": "0.0.0",
24
25
  "@imtbl/checkout-widgets": "0.0.0",
25
26
  "@imtbl/config": "0.0.0",
26
27
  "@imtbl/cryptofiat": "0.0.0",
28
+ "@imtbl/erc20": "0.0.0",
29
+ "@imtbl/erc721-permissioned-mintable": "0.0.0",
30
+ "@imtbl/guardian": "0.0.0",
27
31
  "@imtbl/immutablex-client": "0.0.0",
28
32
  "@imtbl/orderbook": "0.0.0",
29
33
  "@imtbl/passport": "0.0.0",
@@ -56,6 +60,10 @@
56
60
  "types": "./dist/config.d.ts",
57
61
  "import": "./dist/config.js"
58
62
  },
63
+ "./blockchain-data": {
64
+ "types": "./dist/blockchain-data.d.ts",
65
+ "import": "./dist/blockchain-data.js"
66
+ },
59
67
  "./immutablex_client": {
60
68
  "types": "./dist/immutablex_client.d.ts",
61
69
  "import": "./dist/immutablex_client.js"
@@ -79,6 +87,14 @@
79
87
  "./checkout_widgets": {
80
88
  "types": "./dist/checkout_widgets.d.ts",
81
89
  "import": "./dist/checkout_widgets.js"
90
+ },
91
+ "./erc20": {
92
+ "types": "./dist/erc20.d.ts",
93
+ "import": "./dist/erc20.js"
94
+ },
95
+ "./erc721-permissioned-mintable": {
96
+ "types": "./dist/erc721-permissioned-mintable.d.ts",
97
+ "import": "./dist/erc721-permissioned-mintable.js"
82
98
  }
83
99
  },
84
100
  "files": [