@imtbl/sdk 0.1.8-alpha.1 → 0.1.8
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/immutablex_client.js +1 -1
- package/dist/index.cjs +2022 -5721
- package/dist/index.d.ts +6395 -23613
- package/dist/index.js +2027 -5710
- package/dist/passport.d.ts +1 -0
- package/dist/passport.js +511 -14
- package/package.json +1 -25
- package/dist/blockchain-data.d.ts +0 -1598
- package/dist/blockchain-data.js +0 -1258
- package/dist/browser/checkout.js +0 -2
- package/dist/checkout_sdk.d.ts +0 -967
- package/dist/checkout_sdk.js +0 -752
- package/dist/checkout_widgets.d.ts +0 -15428
- package/dist/checkout_widgets.js +0 -281
- package/dist/erc20.d.ts +0 -3
- package/dist/erc20.js +0 -4
- package/dist/erc721-permissioned-mintable.d.ts +0 -3
- package/dist/erc721-permissioned-mintable.js +0 -4
- package/dist/orderbook.d.ts +0 -64
- package/dist/orderbook.js +0 -1913
package/dist/passport.d.ts
CHANGED
|
@@ -10483,6 +10483,7 @@ interface PassportOverrides {
|
|
|
10483
10483
|
magicPublishableApiKey: string;
|
|
10484
10484
|
magicProviderId: string;
|
|
10485
10485
|
passportDomain: string;
|
|
10486
|
+
imxPublicApiDomain: string;
|
|
10486
10487
|
immutableXClient: ImmutableXClient;
|
|
10487
10488
|
}
|
|
10488
10489
|
interface PassportModuleConfiguration extends ModuleConfiguration<PassportOverrides>, OidcConfiguration {
|
package/dist/passport.js
CHANGED
|
@@ -5,6 +5,7 @@ import { Magic } from 'magic-sdk';
|
|
|
5
5
|
import { OpenIdExtension } from '@magic-ext/oidc';
|
|
6
6
|
import BN from 'bn.js';
|
|
7
7
|
import * as encUtils from 'enc-utils';
|
|
8
|
+
import globalAxios from 'axios';
|
|
8
9
|
|
|
9
10
|
var Environment;
|
|
10
11
|
(function (Environment) {
|
|
@@ -21,7 +22,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
21
22
|
chainID,
|
|
22
23
|
coreContractAddress,
|
|
23
24
|
registrationContractAddress,
|
|
24
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
25
|
+
sdkVersion: 'ts-immutable-sdk-0.0.0',
|
|
25
26
|
});
|
|
26
27
|
/**
|
|
27
28
|
* Sets `sdkVersion` at the time of build
|
|
@@ -587,6 +588,426 @@ function convertToSignableToken(token) {
|
|
|
587
588
|
}
|
|
588
589
|
}
|
|
589
590
|
|
|
591
|
+
/* tslint:disable */
|
|
592
|
+
/* eslint-disable */
|
|
593
|
+
/**
|
|
594
|
+
* Swagger Guardian
|
|
595
|
+
* Guardian API
|
|
596
|
+
*
|
|
597
|
+
* The version of the OpenAPI document: 1.0.0
|
|
598
|
+
* Contact: support@immutable.com
|
|
599
|
+
*
|
|
600
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
601
|
+
* https://openapi-generator.tech
|
|
602
|
+
* Do not edit the class manually.
|
|
603
|
+
*/
|
|
604
|
+
const BASE_PATH = "http://guardian.sandbox.imtbl.com".replace(/\/+$/, "");
|
|
605
|
+
/**
|
|
606
|
+
*
|
|
607
|
+
* @export
|
|
608
|
+
* @class BaseAPI
|
|
609
|
+
*/
|
|
610
|
+
class BaseAPI {
|
|
611
|
+
basePath;
|
|
612
|
+
axios;
|
|
613
|
+
configuration;
|
|
614
|
+
constructor(configuration, basePath = BASE_PATH, axios = globalAxios) {
|
|
615
|
+
this.basePath = basePath;
|
|
616
|
+
this.axios = axios;
|
|
617
|
+
if (configuration) {
|
|
618
|
+
this.configuration = configuration;
|
|
619
|
+
this.basePath = configuration.basePath || this.basePath;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
*
|
|
625
|
+
* @export
|
|
626
|
+
* @class RequiredError
|
|
627
|
+
* @extends {Error}
|
|
628
|
+
*/
|
|
629
|
+
class RequiredError extends Error {
|
|
630
|
+
field;
|
|
631
|
+
constructor(field, msg) {
|
|
632
|
+
super(msg);
|
|
633
|
+
this.field = field;
|
|
634
|
+
this.name = "RequiredError";
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/* tslint:disable */
|
|
639
|
+
/* eslint-disable */
|
|
640
|
+
/**
|
|
641
|
+
* Swagger Guardian
|
|
642
|
+
* Guardian API
|
|
643
|
+
*
|
|
644
|
+
* The version of the OpenAPI document: 1.0.0
|
|
645
|
+
* Contact: support@immutable.com
|
|
646
|
+
*
|
|
647
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
648
|
+
* https://openapi-generator.tech
|
|
649
|
+
* Do not edit the class manually.
|
|
650
|
+
*/
|
|
651
|
+
/**
|
|
652
|
+
*
|
|
653
|
+
* @export
|
|
654
|
+
*/
|
|
655
|
+
const DUMMY_BASE_URL = 'https://example.com';
|
|
656
|
+
/**
|
|
657
|
+
*
|
|
658
|
+
* @throws {RequiredError}
|
|
659
|
+
* @export
|
|
660
|
+
*/
|
|
661
|
+
const assertParamExists = function (functionName, paramName, paramValue) {
|
|
662
|
+
if (paramValue === null || paramValue === undefined) {
|
|
663
|
+
throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
/**
|
|
667
|
+
*
|
|
668
|
+
* @export
|
|
669
|
+
*/
|
|
670
|
+
const setBearerAuthToObject = async function (object, configuration) {
|
|
671
|
+
if (configuration && configuration.accessToken) {
|
|
672
|
+
const accessToken = typeof configuration.accessToken === 'function'
|
|
673
|
+
? await configuration.accessToken()
|
|
674
|
+
: await configuration.accessToken;
|
|
675
|
+
object["Authorization"] = "Bearer " + accessToken;
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
|
|
679
|
+
if (parameter == null)
|
|
680
|
+
return;
|
|
681
|
+
if (typeof parameter === "object") {
|
|
682
|
+
if (Array.isArray(parameter)) {
|
|
683
|
+
parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
Object.keys(parameter).forEach(currentKey => setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`));
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
if (urlSearchParams.has(key)) {
|
|
691
|
+
urlSearchParams.append(key, parameter);
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
urlSearchParams.set(key, parameter);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
*
|
|
700
|
+
* @export
|
|
701
|
+
*/
|
|
702
|
+
const setSearchParams = function (url, ...objects) {
|
|
703
|
+
const searchParams = new URLSearchParams(url.search);
|
|
704
|
+
setFlattenedQueryParams(searchParams, objects);
|
|
705
|
+
url.search = searchParams.toString();
|
|
706
|
+
};
|
|
707
|
+
/**
|
|
708
|
+
*
|
|
709
|
+
* @export
|
|
710
|
+
*/
|
|
711
|
+
const toPathString = function (url) {
|
|
712
|
+
return url.pathname + url.search + url.hash;
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
715
|
+
*
|
|
716
|
+
* @export
|
|
717
|
+
*/
|
|
718
|
+
const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) {
|
|
719
|
+
return (axios = globalAxios, basePath = BASE_PATH) => {
|
|
720
|
+
const axiosRequestArgs = { ...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url };
|
|
721
|
+
return axios.request(axiosRequestArgs);
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
/* tslint:disable */
|
|
726
|
+
/* eslint-disable */
|
|
727
|
+
/**
|
|
728
|
+
* Swagger Guardian
|
|
729
|
+
* Guardian API
|
|
730
|
+
*
|
|
731
|
+
* The version of the OpenAPI document: 1.0.0
|
|
732
|
+
* Contact: support@immutable.com
|
|
733
|
+
*
|
|
734
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
735
|
+
* https://openapi-generator.tech
|
|
736
|
+
* Do not edit the class manually.
|
|
737
|
+
*/
|
|
738
|
+
/**
|
|
739
|
+
* StarkexTransactionsApi - axios parameter creator
|
|
740
|
+
* @export
|
|
741
|
+
*/
|
|
742
|
+
const StarkexTransactionsApiAxiosParamCreator = function (configuration) {
|
|
743
|
+
return {
|
|
744
|
+
/**
|
|
745
|
+
* Check if it is a valid transaction by payload hash
|
|
746
|
+
* @summary Evaluate if it is an valid transaction
|
|
747
|
+
* @param {string} payloadHash Hash for the payload
|
|
748
|
+
* @param {*} [options] Override http request option.
|
|
749
|
+
* @throws {RequiredError}
|
|
750
|
+
*/
|
|
751
|
+
evaluateStarkexTransaction: async (payloadHash, options = {}) => {
|
|
752
|
+
// verify required parameter 'payloadHash' is not null or undefined
|
|
753
|
+
assertParamExists('evaluateStarkexTransaction', 'payloadHash', payloadHash);
|
|
754
|
+
const localVarPath = `/guardian/v1/starkex/evaluate/{payloadHash}`
|
|
755
|
+
.replace(`{${"payloadHash"}}`, encodeURIComponent(String(payloadHash)));
|
|
756
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
757
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
758
|
+
let baseOptions;
|
|
759
|
+
if (configuration) {
|
|
760
|
+
baseOptions = configuration.baseOptions;
|
|
761
|
+
}
|
|
762
|
+
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
|
|
763
|
+
const localVarHeaderParameter = {};
|
|
764
|
+
const localVarQueryParameter = {};
|
|
765
|
+
// authentication BearerAuth required
|
|
766
|
+
// http bearer authentication required
|
|
767
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
768
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
769
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
770
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
771
|
+
return {
|
|
772
|
+
url: toPathString(localVarUrlObj),
|
|
773
|
+
options: localVarRequestOptions,
|
|
774
|
+
};
|
|
775
|
+
},
|
|
776
|
+
};
|
|
777
|
+
};
|
|
778
|
+
/**
|
|
779
|
+
* StarkexTransactionsApi - functional programming interface
|
|
780
|
+
* @export
|
|
781
|
+
*/
|
|
782
|
+
const StarkexTransactionsApiFp = function (configuration) {
|
|
783
|
+
const localVarAxiosParamCreator = StarkexTransactionsApiAxiosParamCreator(configuration);
|
|
784
|
+
return {
|
|
785
|
+
/**
|
|
786
|
+
* Check if it is a valid transaction by payload hash
|
|
787
|
+
* @summary Evaluate if it is an valid transaction
|
|
788
|
+
* @param {string} payloadHash Hash for the payload
|
|
789
|
+
* @param {*} [options] Override http request option.
|
|
790
|
+
* @throws {RequiredError}
|
|
791
|
+
*/
|
|
792
|
+
async evaluateStarkexTransaction(payloadHash, options) {
|
|
793
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.evaluateStarkexTransaction(payloadHash, options);
|
|
794
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
795
|
+
},
|
|
796
|
+
};
|
|
797
|
+
};
|
|
798
|
+
/**
|
|
799
|
+
* StarkexTransactionsApi - object-oriented interface
|
|
800
|
+
* @export
|
|
801
|
+
* @class StarkexTransactionsApi
|
|
802
|
+
* @extends {BaseAPI}
|
|
803
|
+
*/
|
|
804
|
+
class StarkexTransactionsApi extends BaseAPI {
|
|
805
|
+
/**
|
|
806
|
+
* Check if it is a valid transaction by payload hash
|
|
807
|
+
* @summary Evaluate if it is an valid transaction
|
|
808
|
+
* @param {StarkexTransactionsApiEvaluateStarkexTransactionRequest} requestParameters Request parameters.
|
|
809
|
+
* @param {*} [options] Override http request option.
|
|
810
|
+
* @throws {RequiredError}
|
|
811
|
+
* @memberof StarkexTransactionsApi
|
|
812
|
+
*/
|
|
813
|
+
evaluateStarkexTransaction(requestParameters, options) {
|
|
814
|
+
return StarkexTransactionsApiFp(this.configuration).evaluateStarkexTransaction(requestParameters.payloadHash, options).then((request) => request(this.axios, this.basePath));
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/* tslint:disable */
|
|
819
|
+
/* eslint-disable */
|
|
820
|
+
/**
|
|
821
|
+
* Swagger Guardian
|
|
822
|
+
* Guardian API
|
|
823
|
+
*
|
|
824
|
+
* The version of the OpenAPI document: 1.0.0
|
|
825
|
+
* Contact: support@immutable.com
|
|
826
|
+
*
|
|
827
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
828
|
+
* https://openapi-generator.tech
|
|
829
|
+
* Do not edit the class manually.
|
|
830
|
+
*/
|
|
831
|
+
/**
|
|
832
|
+
* TransactionsApi - axios parameter creator
|
|
833
|
+
* @export
|
|
834
|
+
*/
|
|
835
|
+
const TransactionsApiAxiosParamCreator = function (configuration) {
|
|
836
|
+
return {
|
|
837
|
+
/**
|
|
838
|
+
* Get a transaction by payload hash
|
|
839
|
+
* @summary Info for a specific transaction
|
|
840
|
+
* @param {string} transactionID The id of the starkex transaction to retrieve
|
|
841
|
+
* @param {string} chainType roll up type
|
|
842
|
+
* @param {number} [chainID] ID of evm chain
|
|
843
|
+
* @param {*} [options] Override http request option.
|
|
844
|
+
* @throws {RequiredError}
|
|
845
|
+
*/
|
|
846
|
+
getTransactionByID: async (transactionID, chainType, chainID, options = {}) => {
|
|
847
|
+
// verify required parameter 'transactionID' is not null or undefined
|
|
848
|
+
assertParamExists('getTransactionByID', 'transactionID', transactionID);
|
|
849
|
+
// verify required parameter 'chainType' is not null or undefined
|
|
850
|
+
assertParamExists('getTransactionByID', 'chainType', chainType);
|
|
851
|
+
const localVarPath = `/guardian/v1/transactions/{transactionID}`
|
|
852
|
+
.replace(`{${"transactionID"}}`, encodeURIComponent(String(transactionID)));
|
|
853
|
+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
854
|
+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
855
|
+
let baseOptions;
|
|
856
|
+
if (configuration) {
|
|
857
|
+
baseOptions = configuration.baseOptions;
|
|
858
|
+
}
|
|
859
|
+
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
|
|
860
|
+
const localVarHeaderParameter = {};
|
|
861
|
+
const localVarQueryParameter = {};
|
|
862
|
+
// authentication BearerAuth required
|
|
863
|
+
// http bearer authentication required
|
|
864
|
+
await setBearerAuthToObject(localVarHeaderParameter, configuration);
|
|
865
|
+
if (chainType !== undefined) {
|
|
866
|
+
localVarQueryParameter['chainType'] = chainType;
|
|
867
|
+
}
|
|
868
|
+
if (chainID !== undefined) {
|
|
869
|
+
localVarQueryParameter['chainID'] = chainID;
|
|
870
|
+
}
|
|
871
|
+
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
872
|
+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
|
873
|
+
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
|
|
874
|
+
return {
|
|
875
|
+
url: toPathString(localVarUrlObj),
|
|
876
|
+
options: localVarRequestOptions,
|
|
877
|
+
};
|
|
878
|
+
},
|
|
879
|
+
};
|
|
880
|
+
};
|
|
881
|
+
/**
|
|
882
|
+
* TransactionsApi - functional programming interface
|
|
883
|
+
* @export
|
|
884
|
+
*/
|
|
885
|
+
const TransactionsApiFp = function (configuration) {
|
|
886
|
+
const localVarAxiosParamCreator = TransactionsApiAxiosParamCreator(configuration);
|
|
887
|
+
return {
|
|
888
|
+
/**
|
|
889
|
+
* Get a transaction by payload hash
|
|
890
|
+
* @summary Info for a specific transaction
|
|
891
|
+
* @param {string} transactionID The id of the starkex transaction to retrieve
|
|
892
|
+
* @param {string} chainType roll up type
|
|
893
|
+
* @param {number} [chainID] ID of evm chain
|
|
894
|
+
* @param {*} [options] Override http request option.
|
|
895
|
+
* @throws {RequiredError}
|
|
896
|
+
*/
|
|
897
|
+
async getTransactionByID(transactionID, chainType, chainID, options) {
|
|
898
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.getTransactionByID(transactionID, chainType, chainID, options);
|
|
899
|
+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
|
900
|
+
},
|
|
901
|
+
};
|
|
902
|
+
};
|
|
903
|
+
/**
|
|
904
|
+
* TransactionsApi - object-oriented interface
|
|
905
|
+
* @export
|
|
906
|
+
* @class TransactionsApi
|
|
907
|
+
* @extends {BaseAPI}
|
|
908
|
+
*/
|
|
909
|
+
class TransactionsApi extends BaseAPI {
|
|
910
|
+
/**
|
|
911
|
+
* Get a transaction by payload hash
|
|
912
|
+
* @summary Info for a specific transaction
|
|
913
|
+
* @param {TransactionsApiGetTransactionByIDRequest} requestParameters Request parameters.
|
|
914
|
+
* @param {*} [options] Override http request option.
|
|
915
|
+
* @throws {RequiredError}
|
|
916
|
+
* @memberof TransactionsApi
|
|
917
|
+
*/
|
|
918
|
+
getTransactionByID(requestParameters, options) {
|
|
919
|
+
return TransactionsApiFp(this.configuration).getTransactionByID(requestParameters.transactionID, requestParameters.chainType, requestParameters.chainID, options).then((request) => request(this.axios, this.basePath));
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/* tslint:disable */
|
|
924
|
+
/* eslint-disable */
|
|
925
|
+
/**
|
|
926
|
+
* Swagger Guardian
|
|
927
|
+
* Guardian API
|
|
928
|
+
*
|
|
929
|
+
* The version of the OpenAPI document: 1.0.0
|
|
930
|
+
* Contact: support@immutable.com
|
|
931
|
+
*
|
|
932
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
933
|
+
* https://openapi-generator.tech
|
|
934
|
+
* Do not edit the class manually.
|
|
935
|
+
*/
|
|
936
|
+
class Configuration {
|
|
937
|
+
/**
|
|
938
|
+
* parameter for apiKey security
|
|
939
|
+
* @param name security name
|
|
940
|
+
* @memberof Configuration
|
|
941
|
+
*/
|
|
942
|
+
apiKey;
|
|
943
|
+
/**
|
|
944
|
+
* parameter for basic security
|
|
945
|
+
*
|
|
946
|
+
* @type {string}
|
|
947
|
+
* @memberof Configuration
|
|
948
|
+
*/
|
|
949
|
+
username;
|
|
950
|
+
/**
|
|
951
|
+
* parameter for basic security
|
|
952
|
+
*
|
|
953
|
+
* @type {string}
|
|
954
|
+
* @memberof Configuration
|
|
955
|
+
*/
|
|
956
|
+
password;
|
|
957
|
+
/**
|
|
958
|
+
* parameter for oauth2 security
|
|
959
|
+
* @param name security name
|
|
960
|
+
* @param scopes oauth2 scope
|
|
961
|
+
* @memberof Configuration
|
|
962
|
+
*/
|
|
963
|
+
accessToken;
|
|
964
|
+
/**
|
|
965
|
+
* override base path
|
|
966
|
+
*
|
|
967
|
+
* @type {string}
|
|
968
|
+
* @memberof Configuration
|
|
969
|
+
*/
|
|
970
|
+
basePath;
|
|
971
|
+
/**
|
|
972
|
+
* base options for axios calls
|
|
973
|
+
*
|
|
974
|
+
* @type {any}
|
|
975
|
+
* @memberof Configuration
|
|
976
|
+
*/
|
|
977
|
+
baseOptions;
|
|
978
|
+
/**
|
|
979
|
+
* The FormData constructor that will be used to create multipart form data
|
|
980
|
+
* requests. You can inject this here so that execution environments that
|
|
981
|
+
* do not support the FormData class can still run the generated client.
|
|
982
|
+
*
|
|
983
|
+
* @type {new () => FormData}
|
|
984
|
+
*/
|
|
985
|
+
formDataCtor;
|
|
986
|
+
constructor(param = {}) {
|
|
987
|
+
this.apiKey = param.apiKey;
|
|
988
|
+
this.username = param.username;
|
|
989
|
+
this.password = param.password;
|
|
990
|
+
this.accessToken = param.accessToken;
|
|
991
|
+
this.basePath = param.basePath;
|
|
992
|
+
this.baseOptions = param.baseOptions;
|
|
993
|
+
this.formDataCtor = param.formDataCtor;
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Check if the given MIME is a JSON MIME.
|
|
997
|
+
* JSON MIME examples:
|
|
998
|
+
* application/json
|
|
999
|
+
* application/json; charset=UTF8
|
|
1000
|
+
* APPLICATION/JSON
|
|
1001
|
+
* application/vnd.company+json
|
|
1002
|
+
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
1003
|
+
* @return True if the given MIME is JSON, false otherwise.
|
|
1004
|
+
*/
|
|
1005
|
+
isJsonMime(mime) {
|
|
1006
|
+
const jsonMime = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
|
1007
|
+
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
590
1011
|
var PassportErrorType;
|
|
591
1012
|
(function (PassportErrorType) {
|
|
592
1013
|
PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
@@ -866,10 +1287,78 @@ class ConfirmationScreen {
|
|
|
866
1287
|
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
867
1288
|
});
|
|
868
1289
|
}
|
|
1290
|
+
startGuardianTransaction(transactionId, popupOptions) {
|
|
1291
|
+
return new Promise((resolve, reject) => {
|
|
1292
|
+
const messageHandler = ({ data, origin }) => {
|
|
1293
|
+
if (origin !== this.config.passportDomain
|
|
1294
|
+
|| data.eventType !== PASSPORT_EVENT_TYPE) {
|
|
1295
|
+
return;
|
|
1296
|
+
}
|
|
1297
|
+
switch (data.messageType) {
|
|
1298
|
+
case ReceiveMessage.CONFIRMATION_WINDOW_READY: {
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
case ReceiveMessage.TRANSACTION_CONFIRMED: {
|
|
1302
|
+
resolve({ confirmed: true });
|
|
1303
|
+
break;
|
|
1304
|
+
}
|
|
1305
|
+
case ReceiveMessage.TRANSACTION_ERROR: {
|
|
1306
|
+
reject(new Error('Transaction error'));
|
|
1307
|
+
break;
|
|
1308
|
+
}
|
|
1309
|
+
default:
|
|
1310
|
+
reject(new Error('Unsupported message type'));
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
window.addEventListener('message', messageHandler);
|
|
1314
|
+
const confirmationWindow = openPopupCenter({
|
|
1315
|
+
// eslint-disable-next-line max-len
|
|
1316
|
+
url: `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&chainType=starkex`,
|
|
1317
|
+
title: CONFIRMATION_WINDOW_TITLE,
|
|
1318
|
+
width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
|
|
1319
|
+
height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
|
|
1320
|
+
});
|
|
1321
|
+
// https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
|
|
1322
|
+
const timer = setInterval(() => {
|
|
1323
|
+
if (confirmationWindow.closed) {
|
|
1324
|
+
clearInterval(timer);
|
|
1325
|
+
window.removeEventListener('message', messageHandler);
|
|
1326
|
+
resolve({ confirmed: false });
|
|
1327
|
+
}
|
|
1328
|
+
}, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
|
|
1329
|
+
});
|
|
1330
|
+
}
|
|
869
1331
|
}
|
|
870
1332
|
|
|
871
1333
|
const ERC721$1 = 'ERC721';
|
|
872
|
-
async
|
|
1334
|
+
const transferWithGuardian = async ({ accessToken, imxPublicApiDomain, payloadHash, confirmationScreen, }) => {
|
|
1335
|
+
const transactionAPI = new TransactionsApi(new Configuration({
|
|
1336
|
+
accessToken,
|
|
1337
|
+
basePath: imxPublicApiDomain,
|
|
1338
|
+
}));
|
|
1339
|
+
const starkExTransactionApi = new StarkexTransactionsApi(new Configuration({
|
|
1340
|
+
accessToken,
|
|
1341
|
+
basePath: imxPublicApiDomain,
|
|
1342
|
+
}));
|
|
1343
|
+
const transactionRes = await retryWithDelay(async () => transactionAPI.getTransactionByID({
|
|
1344
|
+
transactionID: payloadHash,
|
|
1345
|
+
chainType: 'starkex',
|
|
1346
|
+
}));
|
|
1347
|
+
if (!transactionRes.data.id) {
|
|
1348
|
+
throw new Error("Transaction doesn't exists");
|
|
1349
|
+
}
|
|
1350
|
+
const evaluateStarkexRes = await starkExTransactionApi.evaluateStarkexTransaction({
|
|
1351
|
+
payloadHash,
|
|
1352
|
+
});
|
|
1353
|
+
const { confirmationRequired } = evaluateStarkexRes.data;
|
|
1354
|
+
if (confirmationRequired) {
|
|
1355
|
+
const confirmationResult = await confirmationScreen.startGuardianTransaction(payloadHash);
|
|
1356
|
+
if (!confirmationResult.confirmed) {
|
|
1357
|
+
throw new Error('Transaction rejected by user');
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
async function transfer({ request, transfersApi, starkSigner, user, imxPublicApiDomain, confirmationScreen, }) {
|
|
873
1362
|
return withPassportError(async () => {
|
|
874
1363
|
const transferAmount = request.type === ERC721$1 ? '1' : request.amount;
|
|
875
1364
|
const getSignableTransferRequest = {
|
|
@@ -878,16 +1367,18 @@ async function transfer({ request, transfersApi, starkSigner, user, confirmation
|
|
|
878
1367
|
amount: transferAmount,
|
|
879
1368
|
receiver: request.receiver,
|
|
880
1369
|
};
|
|
1370
|
+
const headers = {
|
|
1371
|
+
Authorization: `Bearer ${user.accessToken}`,
|
|
1372
|
+
};
|
|
881
1373
|
const signableResult = await transfersApi.getSignableTransferV1({
|
|
882
1374
|
getSignableTransferRequest,
|
|
1375
|
+
}, { headers });
|
|
1376
|
+
await transferWithGuardian({
|
|
1377
|
+
imxPublicApiDomain,
|
|
1378
|
+
accessToken: user.accessToken,
|
|
1379
|
+
payloadHash: signableResult.data.payload_hash,
|
|
1380
|
+
confirmationScreen,
|
|
883
1381
|
});
|
|
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
1382
|
const signableResultData = signableResult.data;
|
|
892
1383
|
const { payload_hash: payloadHash } = signableResultData;
|
|
893
1384
|
const starkSignature = await starkSigner.signMessage(payloadHash);
|
|
@@ -906,10 +1397,6 @@ async function transfer({ request, transfersApi, starkSigner, user, confirmation
|
|
|
906
1397
|
const createTransferRequest = {
|
|
907
1398
|
createTransferRequest: transferSigningParams,
|
|
908
1399
|
};
|
|
909
|
-
const headers = {
|
|
910
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
911
|
-
Authorization: `Bearer ${user.accessToken}`,
|
|
912
|
-
};
|
|
913
1400
|
const { data: responseData } = await transfersApi.createTransferV1(createTransferRequest, { headers });
|
|
914
1401
|
return {
|
|
915
1402
|
sent_signature: responseData.sent_signature,
|
|
@@ -1165,10 +1652,12 @@ class PassportImxProvider {
|
|
|
1165
1652
|
starkSigner;
|
|
1166
1653
|
immutableXClient;
|
|
1167
1654
|
confirmationScreen;
|
|
1168
|
-
|
|
1655
|
+
imxPublicApiDomain;
|
|
1656
|
+
constructor({ user, starkSigner, immutableXClient, imxPublicApiDomain, confirmationScreen, }) {
|
|
1169
1657
|
this.user = user;
|
|
1170
1658
|
this.starkSigner = starkSigner;
|
|
1171
1659
|
this.immutableXClient = immutableXClient;
|
|
1660
|
+
this.imxPublicApiDomain = imxPublicApiDomain;
|
|
1172
1661
|
this.confirmationScreen = confirmationScreen;
|
|
1173
1662
|
}
|
|
1174
1663
|
async transfer(request) {
|
|
@@ -1178,6 +1667,7 @@ class PassportImxProvider {
|
|
|
1178
1667
|
starkSigner: this.starkSigner,
|
|
1179
1668
|
transfersApi: this.immutableXClient.transfersApi,
|
|
1180
1669
|
confirmationScreen: this.confirmationScreen,
|
|
1670
|
+
imxPublicApiDomain: this.imxPublicApiDomain,
|
|
1181
1671
|
});
|
|
1182
1672
|
}
|
|
1183
1673
|
// TODO: Remove once implemented
|
|
@@ -1280,6 +1770,7 @@ class PassportConfiguration {
|
|
|
1280
1770
|
network;
|
|
1281
1771
|
authenticationDomain;
|
|
1282
1772
|
passportDomain;
|
|
1773
|
+
imxPublicApiDomain;
|
|
1283
1774
|
magicPublishableApiKey;
|
|
1284
1775
|
magicProviderId;
|
|
1285
1776
|
oidcConfiguration;
|
|
@@ -1299,10 +1790,12 @@ class PassportConfiguration {
|
|
|
1299
1790
|
'magicPublishableApiKey',
|
|
1300
1791
|
'magicProviderId',
|
|
1301
1792
|
'passportDomain',
|
|
1793
|
+
'imxPublicApiDomain',
|
|
1302
1794
|
], 'overrides');
|
|
1303
1795
|
this.network = overrides.network;
|
|
1304
1796
|
this.authenticationDomain = overrides.authenticationDomain;
|
|
1305
1797
|
this.passportDomain = overrides.passportDomain;
|
|
1798
|
+
this.imxPublicApiDomain = overrides.imxPublicApiDomain;
|
|
1306
1799
|
this.magicPublishableApiKey = overrides.magicPublishableApiKey;
|
|
1307
1800
|
this.magicProviderId = overrides.magicProviderId;
|
|
1308
1801
|
}
|
|
@@ -1314,6 +1807,7 @@ class PassportConfiguration {
|
|
|
1314
1807
|
this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
|
|
1315
1808
|
this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
|
|
1316
1809
|
this.passportDomain = 'https://passport.immutable.com';
|
|
1810
|
+
this.imxPublicApiDomain = 'https://api.immutable.com';
|
|
1317
1811
|
break;
|
|
1318
1812
|
}
|
|
1319
1813
|
case Environment.SANDBOX:
|
|
@@ -1323,6 +1817,7 @@ class PassportConfiguration {
|
|
|
1323
1817
|
this.magicPublishableApiKey = 'pk_live_10F423798A540ED7';
|
|
1324
1818
|
this.magicProviderId = 'fSMzaRQ4O7p4fttl7pCyGVtJS_G70P8SNsLXtPPGHo0=';
|
|
1325
1819
|
this.passportDomain = 'https://passport.sandbox.immutable.com';
|
|
1820
|
+
this.imxPublicApiDomain = 'https://api.sandbox.immutable.com';
|
|
1326
1821
|
break;
|
|
1327
1822
|
}
|
|
1328
1823
|
}
|
|
@@ -1392,6 +1887,7 @@ class Passport {
|
|
|
1392
1887
|
user: updatedUser,
|
|
1393
1888
|
starkSigner,
|
|
1394
1889
|
immutableXClient: this.immutableXClient,
|
|
1890
|
+
imxPublicApiDomain: this.config.imxPublicApiDomain,
|
|
1395
1891
|
confirmationScreen: this.confirmationScreen,
|
|
1396
1892
|
});
|
|
1397
1893
|
}
|
|
@@ -1400,6 +1896,7 @@ class Passport {
|
|
|
1400
1896
|
user: userWithEtherKey,
|
|
1401
1897
|
starkSigner,
|
|
1402
1898
|
immutableXClient: this.immutableXClient,
|
|
1899
|
+
imxPublicApiDomain: this.config.imxPublicApiDomain,
|
|
1403
1900
|
confirmationScreen: this.confirmationScreen,
|
|
1404
1901
|
});
|
|
1405
1902
|
}
|
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.8
|
|
4
|
+
"version": "0.1.8",
|
|
5
5
|
"author": "Immutable",
|
|
6
6
|
"bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -60,10 +60,6 @@
|
|
|
60
60
|
"types": "./dist/config.d.ts",
|
|
61
61
|
"import": "./dist/config.js"
|
|
62
62
|
},
|
|
63
|
-
"./blockchain-data": {
|
|
64
|
-
"types": "./dist/blockchain-data.d.ts",
|
|
65
|
-
"import": "./dist/blockchain-data.js"
|
|
66
|
-
},
|
|
67
63
|
"./immutablex_client": {
|
|
68
64
|
"types": "./dist/immutablex_client.d.ts",
|
|
69
65
|
"import": "./dist/immutablex_client.js"
|
|
@@ -72,29 +68,9 @@
|
|
|
72
68
|
"types": "./dist/passport.d.ts",
|
|
73
69
|
"import": "./dist/passport.js"
|
|
74
70
|
},
|
|
75
|
-
"./orderbook": {
|
|
76
|
-
"types": "./dist/orderbook.d.ts",
|
|
77
|
-
"import": "./dist/orderbook.js"
|
|
78
|
-
},
|
|
79
71
|
"./provider": {
|
|
80
72
|
"types": "./dist/provider.d.ts",
|
|
81
73
|
"import": "./dist/provider.js"
|
|
82
|
-
},
|
|
83
|
-
"./checkout_sdk": {
|
|
84
|
-
"types": "./dist/checkout_sdk.d.ts",
|
|
85
|
-
"import": "./dist/checkout_sdk.js"
|
|
86
|
-
},
|
|
87
|
-
"./checkout_widgets": {
|
|
88
|
-
"types": "./dist/checkout_widgets.d.ts",
|
|
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"
|
|
98
74
|
}
|
|
99
75
|
},
|
|
100
76
|
"files": [
|