@portal-hq/web 3.8.0 → 3.9.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.
@@ -70,6 +70,16 @@ import {
70
70
  mockScanTokenResponse,
71
71
  mockScanUrlRequest,
72
72
  mockScanUrlResponse,
73
+ mockBlockaidScanEvmTxRequest,
74
+ mockBlockaidScanEvmTxResponse,
75
+ mockBlockaidScanSolanaTxRequest,
76
+ mockBlockaidScanSolanaTxResponse,
77
+ mockBlockaidScanAddressRequest,
78
+ mockBlockaidScanAddressResponse,
79
+ mockBlockaidScanTokensRequest,
80
+ mockBlockaidScanTokensResponse,
81
+ mockBlockaidScanUrlRequest,
82
+ mockBlockaidScanUrlResponse,
73
83
  } from '../__mocks/constants'
74
84
  import portalMock from '../__mocks/portal/portal'
75
85
  import { PortalMpcError } from './errors'
@@ -3882,4 +3892,388 @@ describe('Mpc', () => {
3882
3892
  })
3883
3893
  })
3884
3894
  })
3895
+
3896
+ /*******************************
3897
+ * Blockaid Security Methods Tests
3898
+ *******************************/
3899
+
3900
+ describe('blockaidScanEvmTx', () => {
3901
+ const args = mockBlockaidScanEvmTxRequest
3902
+ const res = mockBlockaidScanEvmTxResponse
3903
+
3904
+ it('should successfully scan EVM transaction with Blockaid', (done) => {
3905
+ jest
3906
+ .spyOn(mpc.iframe?.contentWindow!, 'postMessage')
3907
+ .mockImplementation((message: any, origin?) => {
3908
+ const { type, data } = message
3909
+
3910
+ expect(type).toEqual('portal:blockaid:scanEvmTx')
3911
+ expect(data).toEqual(args)
3912
+ expect(origin).toEqual(mockHostOrigin)
3913
+
3914
+ window.dispatchEvent(
3915
+ new MessageEvent('message', {
3916
+ origin: mockHostOrigin,
3917
+ data: {
3918
+ type: 'portal:blockaid:scanEvmTxResult',
3919
+ data: res,
3920
+ },
3921
+ }),
3922
+ )
3923
+ })
3924
+
3925
+ mpc
3926
+ .blockaidScanEvmTx(args)
3927
+ .then((data) => {
3928
+ expect(data).toEqual(res)
3929
+ done()
3930
+ })
3931
+ .catch((_) => {
3932
+ expect(0).toEqual(1)
3933
+ done()
3934
+ })
3935
+ })
3936
+
3937
+ it('should error out if the iframe sends an error message', (done) => {
3938
+ jest
3939
+ .spyOn(mpc.iframe?.contentWindow!, 'postMessage')
3940
+ .mockImplementationOnce((message: any, origin?) => {
3941
+ const { type, data } = message
3942
+
3943
+ expect(type).toEqual('portal:blockaid:scanEvmTx')
3944
+ expect(data).toEqual(args)
3945
+ expect(origin).toEqual(mockHostOrigin)
3946
+
3947
+ window.dispatchEvent(
3948
+ new MessageEvent('message', {
3949
+ origin: mockHostOrigin,
3950
+ data: {
3951
+ type: 'portal:blockaid:scanEvmTxError',
3952
+ data: {
3953
+ code: 1,
3954
+ message: 'test',
3955
+ },
3956
+ },
3957
+ }),
3958
+ )
3959
+ })
3960
+
3961
+ mpc
3962
+ .blockaidScanEvmTx(args)
3963
+ .then(() => {
3964
+ expect(0).toEqual(1)
3965
+ done()
3966
+ })
3967
+ .catch((e) => {
3968
+ expect(e).toBeInstanceOf(PortalMpcError)
3969
+ expect(e.message).toEqual('test')
3970
+ expect(e.code).toEqual(1)
3971
+ done()
3972
+ })
3973
+ })
3974
+ })
3975
+
3976
+ describe('blockaidScanSolanaTx', () => {
3977
+ const args = mockBlockaidScanSolanaTxRequest
3978
+ const res = mockBlockaidScanSolanaTxResponse
3979
+
3980
+ it('should successfully scan Solana transaction with Blockaid', (done) => {
3981
+ jest
3982
+ .spyOn(mpc.iframe?.contentWindow!, 'postMessage')
3983
+ .mockImplementation((message: any, origin?) => {
3984
+ const { type, data } = message
3985
+
3986
+ expect(type).toEqual('portal:blockaid:scanSolanaTx')
3987
+ expect(data).toEqual(args)
3988
+ expect(origin).toEqual(mockHostOrigin)
3989
+
3990
+ window.dispatchEvent(
3991
+ new MessageEvent('message', {
3992
+ origin: mockHostOrigin,
3993
+ data: {
3994
+ type: 'portal:blockaid:scanSolanaTxResult',
3995
+ data: res,
3996
+ },
3997
+ }),
3998
+ )
3999
+ })
4000
+
4001
+ mpc
4002
+ .blockaidScanSolanaTx(args)
4003
+ .then((data) => {
4004
+ expect(data).toEqual(res)
4005
+ done()
4006
+ })
4007
+ .catch((_) => {
4008
+ expect(0).toEqual(1)
4009
+ done()
4010
+ })
4011
+ })
4012
+
4013
+ it('should error out if the iframe sends an error message', (done) => {
4014
+ jest
4015
+ .spyOn(mpc.iframe?.contentWindow!, 'postMessage')
4016
+ .mockImplementationOnce((message: any, origin?) => {
4017
+ const { type, data } = message
4018
+
4019
+ expect(type).toEqual('portal:blockaid:scanSolanaTx')
4020
+ expect(data).toEqual(args)
4021
+ expect(origin).toEqual(mockHostOrigin)
4022
+
4023
+ window.dispatchEvent(
4024
+ new MessageEvent('message', {
4025
+ origin: mockHostOrigin,
4026
+ data: {
4027
+ type: 'portal:blockaid:scanSolanaTxError',
4028
+ data: {
4029
+ code: 1,
4030
+ message: 'test',
4031
+ },
4032
+ },
4033
+ }),
4034
+ )
4035
+ })
4036
+
4037
+ mpc
4038
+ .blockaidScanSolanaTx(args)
4039
+ .then(() => {
4040
+ expect(0).toEqual(1)
4041
+ done()
4042
+ })
4043
+ .catch((e) => {
4044
+ expect(e).toBeInstanceOf(PortalMpcError)
4045
+ expect(e.message).toEqual('test')
4046
+ expect(e.code).toEqual(1)
4047
+ done()
4048
+ })
4049
+ })
4050
+ })
4051
+
4052
+ describe('blockaidScanAddress', () => {
4053
+ const args = mockBlockaidScanAddressRequest
4054
+ const res = mockBlockaidScanAddressResponse
4055
+
4056
+ it('should successfully scan address with Blockaid', (done) => {
4057
+ jest
4058
+ .spyOn(mpc.iframe?.contentWindow!, 'postMessage')
4059
+ .mockImplementation((message: any, origin?) => {
4060
+ const { type, data } = message
4061
+
4062
+ expect(type).toEqual('portal:blockaid:scanAddress')
4063
+ expect(data).toEqual(args)
4064
+ expect(origin).toEqual(mockHostOrigin)
4065
+
4066
+ window.dispatchEvent(
4067
+ new MessageEvent('message', {
4068
+ origin: mockHostOrigin,
4069
+ data: {
4070
+ type: 'portal:blockaid:scanAddressResult',
4071
+ data: res,
4072
+ },
4073
+ }),
4074
+ )
4075
+ })
4076
+
4077
+ mpc
4078
+ .blockaidScanAddress(args)
4079
+ .then((data) => {
4080
+ expect(data).toEqual(res)
4081
+ done()
4082
+ })
4083
+ .catch((_) => {
4084
+ expect(0).toEqual(1)
4085
+ done()
4086
+ })
4087
+ })
4088
+
4089
+ it('should error out if the iframe sends an error message', (done) => {
4090
+ jest
4091
+ .spyOn(mpc.iframe?.contentWindow!, 'postMessage')
4092
+ .mockImplementationOnce((message: any, origin?) => {
4093
+ const { type, data } = message
4094
+
4095
+ expect(type).toEqual('portal:blockaid:scanAddress')
4096
+ expect(data).toEqual(args)
4097
+ expect(origin).toEqual(mockHostOrigin)
4098
+
4099
+ window.dispatchEvent(
4100
+ new MessageEvent('message', {
4101
+ origin: mockHostOrigin,
4102
+ data: {
4103
+ type: 'portal:blockaid:scanAddressError',
4104
+ data: {
4105
+ code: 1,
4106
+ message: 'test',
4107
+ },
4108
+ },
4109
+ }),
4110
+ )
4111
+ })
4112
+
4113
+ mpc
4114
+ .blockaidScanAddress(args)
4115
+ .then(() => {
4116
+ expect(0).toEqual(1)
4117
+ done()
4118
+ })
4119
+ .catch((e) => {
4120
+ expect(e).toBeInstanceOf(PortalMpcError)
4121
+ expect(e.message).toEqual('test')
4122
+ expect(e.code).toEqual(1)
4123
+ done()
4124
+ })
4125
+ })
4126
+ })
4127
+
4128
+ describe('blockaidScanTokens', () => {
4129
+ const args = mockBlockaidScanTokensRequest
4130
+ const res = mockBlockaidScanTokensResponse
4131
+
4132
+ it('should successfully scan tokens with Blockaid', (done) => {
4133
+ jest
4134
+ .spyOn(mpc.iframe?.contentWindow!, 'postMessage')
4135
+ .mockImplementation((message: any, origin?) => {
4136
+ const { type, data } = message
4137
+
4138
+ expect(type).toEqual('portal:blockaid:scanTokens')
4139
+ expect(data).toEqual(args)
4140
+ expect(origin).toEqual(mockHostOrigin)
4141
+
4142
+ window.dispatchEvent(
4143
+ new MessageEvent('message', {
4144
+ origin: mockHostOrigin,
4145
+ data: {
4146
+ type: 'portal:blockaid:scanTokensResult',
4147
+ data: res,
4148
+ },
4149
+ }),
4150
+ )
4151
+ })
4152
+
4153
+ mpc
4154
+ .blockaidScanTokens(args)
4155
+ .then((data) => {
4156
+ expect(data).toEqual(res)
4157
+ done()
4158
+ })
4159
+ .catch((_) => {
4160
+ expect(0).toEqual(1)
4161
+ done()
4162
+ })
4163
+ })
4164
+
4165
+ it('should error out if the iframe sends an error message', (done) => {
4166
+ jest
4167
+ .spyOn(mpc.iframe?.contentWindow!, 'postMessage')
4168
+ .mockImplementationOnce((message: any, origin?) => {
4169
+ const { type, data } = message
4170
+
4171
+ expect(type).toEqual('portal:blockaid:scanTokens')
4172
+ expect(data).toEqual(args)
4173
+ expect(origin).toEqual(mockHostOrigin)
4174
+
4175
+ window.dispatchEvent(
4176
+ new MessageEvent('message', {
4177
+ origin: mockHostOrigin,
4178
+ data: {
4179
+ type: 'portal:blockaid:scanTokensError',
4180
+ data: {
4181
+ code: 1,
4182
+ message: 'test',
4183
+ },
4184
+ },
4185
+ }),
4186
+ )
4187
+ })
4188
+
4189
+ mpc
4190
+ .blockaidScanTokens(args)
4191
+ .then(() => {
4192
+ expect(0).toEqual(1)
4193
+ done()
4194
+ })
4195
+ .catch((e) => {
4196
+ expect(e).toBeInstanceOf(PortalMpcError)
4197
+ expect(e.message).toEqual('test')
4198
+ expect(e.code).toEqual(1)
4199
+ done()
4200
+ })
4201
+ })
4202
+ })
4203
+
4204
+ describe('blockaidScanUrl', () => {
4205
+ const args = mockBlockaidScanUrlRequest
4206
+ const res = mockBlockaidScanUrlResponse
4207
+
4208
+ it('should successfully scan URL with Blockaid', (done) => {
4209
+ jest
4210
+ .spyOn(mpc.iframe?.contentWindow!, 'postMessage')
4211
+ .mockImplementation((message: any, origin?) => {
4212
+ const { type, data } = message
4213
+
4214
+ expect(type).toEqual('portal:blockaid:scanUrl')
4215
+ expect(data).toEqual(args)
4216
+ expect(origin).toEqual(mockHostOrigin)
4217
+
4218
+ window.dispatchEvent(
4219
+ new MessageEvent('message', {
4220
+ origin: mockHostOrigin,
4221
+ data: {
4222
+ type: 'portal:blockaid:scanUrlResult',
4223
+ data: res,
4224
+ },
4225
+ }),
4226
+ )
4227
+ })
4228
+
4229
+ mpc
4230
+ .blockaidScanUrl(args)
4231
+ .then((data) => {
4232
+ expect(data).toEqual(res)
4233
+ done()
4234
+ })
4235
+ .catch((_) => {
4236
+ expect(0).toEqual(1)
4237
+ done()
4238
+ })
4239
+ })
4240
+
4241
+ it('should error out if the iframe sends an error message', (done) => {
4242
+ jest
4243
+ .spyOn(mpc.iframe?.contentWindow!, 'postMessage')
4244
+ .mockImplementationOnce((message: any, origin?) => {
4245
+ const { type, data } = message
4246
+
4247
+ expect(type).toEqual('portal:blockaid:scanUrl')
4248
+ expect(data).toEqual(args)
4249
+ expect(origin).toEqual(mockHostOrigin)
4250
+
4251
+ window.dispatchEvent(
4252
+ new MessageEvent('message', {
4253
+ origin: mockHostOrigin,
4254
+ data: {
4255
+ type: 'portal:blockaid:scanUrlError',
4256
+ data: {
4257
+ code: 1,
4258
+ message: 'test',
4259
+ },
4260
+ },
4261
+ }),
4262
+ )
4263
+ })
4264
+
4265
+ mpc
4266
+ .blockaidScanUrl(args)
4267
+ .then(() => {
4268
+ expect(0).toEqual(1)
4269
+ done()
4270
+ })
4271
+ .catch((e) => {
4272
+ expect(e).toBeInstanceOf(PortalMpcError)
4273
+ expect(e.message).toEqual('test')
4274
+ expect(e.code).toEqual(1)
4275
+ done()
4276
+ })
4277
+ })
4278
+ })
3885
4279
  })
package/src/mpc/index.ts CHANGED
@@ -83,10 +83,20 @@ import {
83
83
  ScanTokensResponse,
84
84
  ScanUrlRequest,
85
85
  ScanUrlResponse,
86
+ BlockaidScanEvmTxRequest,
87
+ BlockaidScanEvmTxResponse,
88
+ BlockaidScanSolanaTxRequest,
89
+ BlockaidScanSolanaTxResponse,
90
+ BlockaidAddressScanRequest,
91
+ BlockaidAddressScanResponse,
92
+ BlockaidBulkTokenScanRequest,
93
+ BlockaidBulkTokenScanResponse,
94
+ BlockaidSiteScanRequest,
95
+ BlockaidSiteScanResponse,
86
96
  } from '../shared/types'
87
97
  import { ScreenAddressApiResponse, ScreenAddressRequestOptions } from '../../hypernative'
88
98
 
89
- const WEB_SDK_VERSION = '3.8.0'
99
+ const WEB_SDK_VERSION = '3.9.0'
90
100
 
91
101
  class Mpc {
92
102
  public iframe?: HTMLIFrameElement
@@ -716,6 +726,65 @@ class Mpc {
716
726
  })
717
727
  }
718
728
 
729
+ /*******************************
730
+ * Blockaid Security Methods
731
+ *******************************/
732
+
733
+ public async blockaidScanEvmTx(
734
+ data: BlockaidScanEvmTxRequest,
735
+ ): Promise<BlockaidScanEvmTxResponse> {
736
+ return this.handleRequestToIframeAndPost({
737
+ methodMessage: 'portal:blockaid:scanEvmTx',
738
+ errorMessage: 'portal:blockaid:scanEvmTxError',
739
+ resultMessage: 'portal:blockaid:scanEvmTxResult',
740
+ data,
741
+ })
742
+ }
743
+
744
+ public async blockaidScanSolanaTx(
745
+ data: BlockaidScanSolanaTxRequest,
746
+ ): Promise<BlockaidScanSolanaTxResponse> {
747
+ return this.handleRequestToIframeAndPost({
748
+ methodMessage: 'portal:blockaid:scanSolanaTx',
749
+ errorMessage: 'portal:blockaid:scanSolanaTxError',
750
+ resultMessage: 'portal:blockaid:scanSolanaTxResult',
751
+ data,
752
+ })
753
+ }
754
+
755
+ public async blockaidScanAddress(
756
+ data: BlockaidAddressScanRequest,
757
+ ): Promise<BlockaidAddressScanResponse> {
758
+ return this.handleRequestToIframeAndPost({
759
+ methodMessage: 'portal:blockaid:scanAddress',
760
+ errorMessage: 'portal:blockaid:scanAddressError',
761
+ resultMessage: 'portal:blockaid:scanAddressResult',
762
+ data,
763
+ })
764
+ }
765
+
766
+ public async blockaidScanTokens(
767
+ data: BlockaidBulkTokenScanRequest,
768
+ ): Promise<BlockaidBulkTokenScanResponse> {
769
+ return this.handleRequestToIframeAndPost({
770
+ methodMessage: 'portal:blockaid:scanTokens',
771
+ errorMessage: 'portal:blockaid:scanTokensError',
772
+ resultMessage: 'portal:blockaid:scanTokensResult',
773
+ data,
774
+ })
775
+ }
776
+
777
+ public async blockaidScanUrl(
778
+ data: BlockaidSiteScanRequest,
779
+ ): Promise<BlockaidSiteScanResponse> {
780
+ return this.handleRequestToIframeAndPost({
781
+ methodMessage: 'portal:blockaid:scanUrl',
782
+ errorMessage: 'portal:blockaid:scanUrlError',
783
+ resultMessage: 'portal:blockaid:scanUrlResult',
784
+ data,
785
+ })
786
+ }
787
+
719
788
  /***************************
720
789
  * Private Methods
721
790
  ***************************/