@openfort/openfort-js 0.7.2 → 0.7.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/index.cjs CHANGED
@@ -4,10 +4,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var hash = require('@ethersproject/hash');
6
6
  var globalAxios = require('axios');
7
+ var providers = require('@ethersproject/providers');
8
+ var bytes = require('@ethersproject/bytes');
9
+ var events = require('events');
10
+ var uuid = require('uuid');
7
11
  var jose = require('jose');
8
12
  var secp256k1 = require('@noble/curves/secp256k1');
9
13
  var signingKey = require('@ethersproject/signing-key');
10
- var bytes = require('@ethersproject/bytes');
11
14
  var transactions = require('@ethersproject/transactions');
12
15
 
13
16
  exports.EmbeddedState = void 0;
@@ -18,6 +21,10 @@ exports.EmbeddedState = void 0;
18
21
  EmbeddedState[EmbeddedState["CREATING_ACCOUNT"] = 3] = "CREATING_ACCOUNT";
19
22
  EmbeddedState[EmbeddedState["READY"] = 4] = "READY";
20
23
  })(exports.EmbeddedState || (exports.EmbeddedState = {}));
24
+ var OpenfortEvents;
25
+ (function (OpenfortEvents) {
26
+ OpenfortEvents["LOGGED_OUT"] = "loggedOut";
27
+ })(OpenfortEvents || (OpenfortEvents = {}));
21
28
  var AccountType;
22
29
  (function (AccountType) {
23
30
  AccountType["UPGRADEABLE_V4"] = "Upgradeable_v04";
@@ -3049,6 +3056,1446 @@ class SDKConfiguration {
3049
3056
  }
3050
3057
  }
3051
3058
 
3059
+ const chain$m = {
3060
+ chain: 'BSC',
3061
+ chainId: 56,
3062
+ explorers: [
3063
+ {
3064
+ name: 'bscscan',
3065
+ url: 'https://bscscan.com',
3066
+ standard: 'EIP3091',
3067
+ },
3068
+ {
3069
+ name: 'dexguru',
3070
+ url: 'https://bnb.dex.guru',
3071
+ standard: 'EIP3091',
3072
+ icon: {
3073
+ url: 'ipfs://QmRaASKRSjQ5btoUQ2rNTJNxKtx2a2RoewgA7DMQkLVEne',
3074
+ width: 83,
3075
+ height: 82,
3076
+ format: 'svg',
3077
+ },
3078
+ },
3079
+ ],
3080
+ faucets: [],
3081
+ features: [],
3082
+ icon: {
3083
+ url: 'ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/binance-coin/512.png',
3084
+ width: 512,
3085
+ height: 512,
3086
+ format: 'png',
3087
+ },
3088
+ infoURL: 'https://www.bnbchain.org/en',
3089
+ name: 'BNB Smart Chain Mainnet',
3090
+ nativeCurrency: {
3091
+ name: 'BNB Chain Native Token',
3092
+ symbol: 'BNB',
3093
+ decimals: 18,
3094
+ },
3095
+ networkId: 56,
3096
+ redFlags: [],
3097
+ rpc: [
3098
+ 'https://bsc.publicnode.com',
3099
+ 'https://bsc-dataseed1.bnbchain.org',
3100
+ 'https://bsc-dataseed2.bnbchain.org',
3101
+ 'https://bsc-dataseed3.bnbchain.org',
3102
+ 'https://bsc-dataseed4.bnbchain.org',
3103
+ 'https://bsc-dataseed1.defibit.io',
3104
+ 'https://bsc-dataseed2.defibit.io',
3105
+ 'https://bsc-dataseed3.defibit.io',
3106
+ 'https://bsc-dataseed4.defibit.io',
3107
+ 'https://bsc-dataseed1.ninicoin.io',
3108
+ 'https://bsc-dataseed2.ninicoin.io',
3109
+ 'https://bsc-dataseed3.ninicoin.io',
3110
+ 'https://bsc-dataseed4.ninicoin.io',
3111
+ 'wss://bsc.publicnode.com',
3112
+ 'wss://bsc-ws-node.nariox.org',
3113
+ ],
3114
+ shortName: 'bnb',
3115
+ slip44: 714,
3116
+ slug: 'binance',
3117
+ testnet: false,
3118
+ };
3119
+
3120
+ const chain$l = {
3121
+ chain: 'BSC',
3122
+ chainId: 97,
3123
+ explorers: [
3124
+ {
3125
+ name: 'bscscan-testnet',
3126
+ url: 'https://testnet.bscscan.com',
3127
+ standard: 'EIP3091',
3128
+ },
3129
+ ],
3130
+ faucets: ['https://testnet.bnbchain.org/faucet-smart'],
3131
+ features: [],
3132
+ icon: {
3133
+ url: 'ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/binance-coin/512.png',
3134
+ width: 512,
3135
+ height: 512,
3136
+ format: 'png',
3137
+ },
3138
+ infoURL: 'https://www.bnbchain.org/en',
3139
+ name: 'BNB Smart Chain Testnet',
3140
+ nativeCurrency: {
3141
+ name: 'BNB Chain Native Token',
3142
+ symbol: 'tBNB',
3143
+ decimals: 18,
3144
+ },
3145
+ networkId: 97,
3146
+ redFlags: [],
3147
+ rpc: [
3148
+ 'https://bsc-testnet.publicnode.com',
3149
+ 'https://data-seed-prebsc-1-s1.bnbchain.org:8545',
3150
+ 'https://data-seed-prebsc-2-s1.bnbchain.org:8545',
3151
+ 'https://data-seed-prebsc-1-s2.bnbchain.org:8545',
3152
+ 'https://data-seed-prebsc-2-s2.bnbchain.org:8545',
3153
+ 'https://data-seed-prebsc-1-s3.bnbchain.org:8545',
3154
+ 'https://data-seed-prebsc-2-s3.bnbchain.org:8545',
3155
+ ],
3156
+ shortName: 'bnbt',
3157
+ slug: 'binance-testnet',
3158
+ testnet: true,
3159
+ };
3160
+
3161
+ const chain$k = {
3162
+ name: 'Base',
3163
+ chain: 'ETH',
3164
+ rpc: [
3165
+ 'https://mainnet.base.org',
3166
+ ],
3167
+ faucets: [],
3168
+ nativeCurrency: {
3169
+ name: 'Ether',
3170
+ symbol: 'ETH',
3171
+ decimals: 18,
3172
+ },
3173
+ infoURL: 'https://base.org',
3174
+ shortName: 'base',
3175
+ chainId: 8453,
3176
+ networkId: 8453,
3177
+ icon: {
3178
+ url: 'ipfs://QmW5Vn15HeRkScMfPcW12ZdZcC2yUASpu6eCsECRdEmjjj/base-512.png',
3179
+ height: 512,
3180
+ width: 512,
3181
+ format: 'png',
3182
+ },
3183
+ explorers: [
3184
+ {
3185
+ name: 'basescout',
3186
+ url: 'https://base.blockscout.com',
3187
+ icon: {
3188
+ url: 'ipfs://QmYtUimyqHkkFxYdbXXRbUqNg2VLPUg6Uu2C2nmFWowiZM',
3189
+ width: 551,
3190
+ height: 540,
3191
+ format: 'png',
3192
+ },
3193
+ standard: 'EIP3091',
3194
+ },
3195
+ {
3196
+ name: 'basescan',
3197
+ url: 'https://basescan.org',
3198
+ standard: 'none',
3199
+ },
3200
+ ],
3201
+ status: 'active',
3202
+ testnet: false,
3203
+ slug: 'base',
3204
+ };
3205
+
3206
+ const chain$j = {
3207
+ chain: 'ETH',
3208
+ chainId: 84532,
3209
+ explorers: [
3210
+ {
3211
+ name: 'basescout',
3212
+ url: 'https://base-sepolia.blockscout.com',
3213
+ standard: 'EIP3091',
3214
+ icon: {
3215
+ url: 'ipfs://QmYtUimyqHkkFxYdbXXRbUqNg2VLPUg6Uu2C2nmFWowiZM',
3216
+ width: 551,
3217
+ height: 540,
3218
+ format: 'png',
3219
+ },
3220
+ },
3221
+ ],
3222
+ faucets: [],
3223
+ icon: {
3224
+ url: 'ipfs://QmaxRoHpxZd8PqccAynherrMznMufG6sdmHZLihkECXmZv',
3225
+ width: 1200,
3226
+ height: 1200,
3227
+ format: 'png',
3228
+ },
3229
+ infoURL: 'https://base.org',
3230
+ name: 'Base Sepolia Testnet',
3231
+ nativeCurrency: {
3232
+ name: 'Sepolia Ether',
3233
+ symbol: 'ETH',
3234
+ decimals: 18,
3235
+ },
3236
+ networkId: 84532,
3237
+ rpc: [
3238
+ 'https://sepolia.base.org',
3239
+ ],
3240
+ shortName: 'basesep',
3241
+ slug: 'base-sepolia-testnet',
3242
+ testnet: true,
3243
+ };
3244
+
3245
+ const chain$i = {
3246
+ name: 'Beam',
3247
+ chainId: 4337,
3248
+ chain: 'BEAM',
3249
+ shortName: 'Beam',
3250
+ slug: 'beam',
3251
+ icon: {
3252
+ url: 'ipfs://QmQJ21NWyGGDraicVEzS1Uqq1yXahM9NCuNZgnfYvtspdt',
3253
+ height: 512,
3254
+ width: 512,
3255
+ format: 'png',
3256
+ },
3257
+ features: [
3258
+ {
3259
+ name: 'EIP1559',
3260
+ },
3261
+ ],
3262
+ nativeCurrency: {
3263
+ name: 'Beam',
3264
+ symbol: 'BEAM',
3265
+ decimals: 18,
3266
+ },
3267
+ rpc: [
3268
+ 'https://eu.build.onbeam.com/rpc/14bfbcc5-49c1-40e8-82c2-025c9a1834e1',
3269
+ ],
3270
+ faucets: ['https://faucet.onbeam.com'],
3271
+ explorers: [
3272
+ {
3273
+ name: 'Beam Explorer',
3274
+ url: 'https://subnets.avax.network/beam/',
3275
+ standard: 'EIP3091',
3276
+ },
3277
+ ],
3278
+ infoURL: 'https://gaming.meritcircle.io/',
3279
+ testnet: false,
3280
+ };
3281
+
3282
+ const chain$h = {
3283
+ name: 'Beam Testnet',
3284
+ chainId: 13337,
3285
+ chain: 'BEAM',
3286
+ shortName: 'Beam Testnet',
3287
+ slug: 'beam-testnet',
3288
+ features: [
3289
+ {
3290
+ name: 'EIP1559',
3291
+ },
3292
+ ],
3293
+ icon: {
3294
+ url: 'ipfs://QmQJ21NWyGGDraicVEzS1Uqq1yXahM9NCuNZgnfYvtspdt',
3295
+ height: 512,
3296
+ width: 512,
3297
+ format: 'png',
3298
+ },
3299
+ nativeCurrency: {
3300
+ name: 'Beam',
3301
+ symbol: 'BEAM',
3302
+ decimals: 18,
3303
+ },
3304
+ rpc: [
3305
+ 'https://eu.build.onbeam.com/rpc/testnet/14bfbcc5-49c1-40e8-82c2-025c9a1834e1',
3306
+ ],
3307
+ faucets: ['https://faucet.avax.network/?subnet=beam', 'https://faucet.onbeam.com'],
3308
+ explorers: [
3309
+ {
3310
+ name: 'Beam Explorer',
3311
+ url: 'https://subnets-test.avax.network/beam',
3312
+ standard: 'EIP3091',
3313
+ },
3314
+ ],
3315
+ infoURL: 'https://www.onbeam.com',
3316
+ testnet: true,
3317
+ };
3318
+
3319
+ const chain$g = {
3320
+ chain: 'AVAX',
3321
+ chainId: 43113,
3322
+ explorers: [
3323
+ {
3324
+ name: 'snowtrace',
3325
+ url: 'https://testnet.snowtrace.io',
3326
+ standard: 'EIP3091',
3327
+ },
3328
+ ],
3329
+ faucets: ['https://faucet.avax-test.network/'],
3330
+ features: [],
3331
+ icon: {
3332
+ url: 'ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/avalanche/512.png',
3333
+ width: 512,
3334
+ height: 512,
3335
+ format: 'png',
3336
+ },
3337
+ infoURL: 'https://cchain.explorer.avax-test.network',
3338
+ name: 'Avalanche Fuji Testnet',
3339
+ nativeCurrency: {
3340
+ name: 'Avalanche',
3341
+ symbol: 'AVAX',
3342
+ decimals: 18,
3343
+ },
3344
+ networkId: 43113,
3345
+ redFlags: [],
3346
+ rpc: [
3347
+ 'https://api.avax-test.network/ext/bc/C/rpc',
3348
+ 'https://avalanche-fuji-c-chain.publicnode.com',
3349
+ ],
3350
+ shortName: 'Fuji',
3351
+ slug: 'avalanche-fuji',
3352
+ testnet: true,
3353
+ };
3354
+
3355
+ const chain$f = {
3356
+ chain: 'AVAX',
3357
+ chainId: 43114,
3358
+ explorers: [
3359
+ {
3360
+ name: 'snowtrace',
3361
+ url: 'https://snowtrace.io',
3362
+ standard: 'EIP3091',
3363
+ },
3364
+ ],
3365
+ faucets: [],
3366
+ features: [
3367
+ {
3368
+ name: 'EIP1559',
3369
+ },
3370
+ ],
3371
+ icon: {
3372
+ url: 'ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/avalanche/512.png',
3373
+ width: 512,
3374
+ height: 512,
3375
+ format: 'png',
3376
+ },
3377
+ infoURL: 'https://www.avax.network/',
3378
+ name: 'Avalanche C-Chain',
3379
+ nativeCurrency: {
3380
+ name: 'Avalanche',
3381
+ symbol: 'AVAX',
3382
+ decimals: 18,
3383
+ },
3384
+ networkId: 43114,
3385
+ redFlags: [],
3386
+ rpc: [
3387
+ 'https://api.avax.network/ext/bc/C/rpc',
3388
+ 'https://avalanche-c-chain.publicnode.com',
3389
+ ],
3390
+ shortName: 'avax',
3391
+ slip44: 9005,
3392
+ slug: 'avalanche',
3393
+ testnet: false,
3394
+ };
3395
+
3396
+ const chain$e = {
3397
+ chain: 'ETH',
3398
+ chainId: 11155111,
3399
+ explorers: [
3400
+ {
3401
+ name: 'etherscan-sepolia',
3402
+ url: 'https://sepolia.etherscan.io',
3403
+ standard: 'EIP3091',
3404
+ },
3405
+ {
3406
+ name: 'otterscan-sepolia',
3407
+ url: 'https://sepolia.otterscan.io',
3408
+ standard: 'EIP3091',
3409
+ },
3410
+ ],
3411
+ faucets: ['http://fauceth.komputing.org?chain=11155111'],
3412
+ features: [],
3413
+ icon: {
3414
+ url: 'ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/ethereum/512.png',
3415
+ width: 512,
3416
+ height: 512,
3417
+ format: 'png',
3418
+ },
3419
+ infoURL: 'https://sepolia.otterscan.io',
3420
+ name: 'Sepolia',
3421
+ nativeCurrency: {
3422
+ name: 'Sepolia Ether',
3423
+ symbol: 'ETH',
3424
+ decimals: 18,
3425
+ },
3426
+ networkId: 11155111,
3427
+ redFlags: [],
3428
+ rpc: [
3429
+ 'https://rpc.sepolia.org',
3430
+ 'https://rpc2.sepolia.org',
3431
+ 'https://rpc-sepolia.rockx.com',
3432
+ 'https://rpc.sepolia.ethpandaops.io',
3433
+ 'https://sepolia.gateway.tenderly.co',
3434
+ 'https://ethereum-sepolia.publicnode.com',
3435
+ ],
3436
+ shortName: 'sep',
3437
+ slug: 'sepolia',
3438
+ testnet: true,
3439
+ title: 'Ethereum Testnet Sepolia',
3440
+ };
3441
+
3442
+ const chain$d = {
3443
+ chain: 'ETH',
3444
+ chainId: 59140,
3445
+ explorers: [
3446
+ {
3447
+ name: 'Etherscan',
3448
+ url: 'https://goerli.lineascan.build',
3449
+ standard: 'EIP3091',
3450
+ icon: {
3451
+ url: 'ipfs://QmURjritnHL7a8TwZgsFwp3f272DJmG5paaPtWDZ98QZwH',
3452
+ width: 97,
3453
+ height: 102,
3454
+ format: 'svg',
3455
+ },
3456
+ },
3457
+ {
3458
+ name: 'Blockscout',
3459
+ url: 'https://explorer.goerli.linea.build',
3460
+ standard: 'EIP3091',
3461
+ icon: {
3462
+ url: 'ipfs://QmURjritnHL7a8TwZgsFwp3f272DJmG5paaPtWDZ98QZwH',
3463
+ width: 97,
3464
+ height: 102,
3465
+ format: 'svg',
3466
+ },
3467
+ },
3468
+ ],
3469
+ faucets: ['https://faucetlink.to/goerli'],
3470
+ icon: {
3471
+ url: 'ipfs://QmURjritnHL7a8TwZgsFwp3f272DJmG5paaPtWDZ98QZwH',
3472
+ width: 97,
3473
+ height: 102,
3474
+ format: 'svg',
3475
+ },
3476
+ infoURL: 'https://linea.build',
3477
+ name: 'Linea Testnet',
3478
+ nativeCurrency: {
3479
+ name: 'Linea Ether',
3480
+ symbol: 'ETH',
3481
+ decimals: 18,
3482
+ },
3483
+ networkId: 59140,
3484
+ parent: {
3485
+ type: 'L2',
3486
+ chain: 'eip155-5',
3487
+ bridges: [
3488
+ {
3489
+ url: 'https://goerli.hop.exchange/#/send?token=ETH&sourceNetwork=ethereum&destNetwork=linea',
3490
+ },
3491
+ ],
3492
+ },
3493
+ rpc: [
3494
+ 'https://rpc.goerli.linea.build',
3495
+ 'wss://rpc.goerli.linea.build',
3496
+ ],
3497
+ shortName: 'linea-testnet',
3498
+ slug: 'linea-testnet',
3499
+ status: 'active',
3500
+ testnet: true,
3501
+ title: 'Linea Goerli Testnet',
3502
+ };
3503
+
3504
+ const chain$c = {
3505
+ chain: 'GNO',
3506
+ chainId: 10200,
3507
+ explorers: [
3508
+ {
3509
+ name: 'blockscout',
3510
+ url: 'https://gnosis-chiado.blockscout.com',
3511
+ standard: 'EIP3091',
3512
+ icon: {
3513
+ url: 'ipfs://QmYtUimyqHkkFxYdbXXRbUqNg2VLPUg6Uu2C2nmFWowiZM',
3514
+ width: 551,
3515
+ height: 540,
3516
+ format: 'png',
3517
+ },
3518
+ },
3519
+ ],
3520
+ faucets: ['https://gnosisfaucet.com'],
3521
+ icon: {
3522
+ url: 'ipfs://bafybeidk4swpgdyqmpz6shd5onvpaujvwiwthrhypufnwr6xh3dausz2dm',
3523
+ width: 1800,
3524
+ height: 1800,
3525
+ format: 'png',
3526
+ },
3527
+ infoURL: 'https://docs.gnosischain.com',
3528
+ name: 'Gnosis Chiado Testnet',
3529
+ nativeCurrency: {
3530
+ name: 'Chiado xDAI',
3531
+ symbol: 'XDAI',
3532
+ decimals: 18,
3533
+ },
3534
+ networkId: 10200,
3535
+ rpc: [
3536
+ 'https://rpc.chiadochain.net',
3537
+ 'https://rpc.chiado.gnosis.gateway.fm',
3538
+ 'wss://rpc.chiadochain.net/wss',
3539
+ 'https://gnosis-chiado-rpc.publicnode.com',
3540
+ 'wss://gnosis-chiado-rpc.publicnode.com',
3541
+ 'https://gnosis-chiado.drpc.org',
3542
+ 'wss://gnosis-chiado.drpc.org',
3543
+ ],
3544
+ shortName: 'chi',
3545
+ slip44: 1,
3546
+ slug: 'gnosis-chiado-testnet',
3547
+ testnet: true,
3548
+ };
3549
+
3550
+ const chain$b = {
3551
+ chain: 'Immutable zkEVM',
3552
+ chainId: 13371,
3553
+ explorers: [
3554
+ {
3555
+ name: 'Immutable explorer',
3556
+ url: 'https://explorer.immutable.com',
3557
+ standard: 'EIP3091',
3558
+ icon: {
3559
+ url: 'ipfs://QmXFUYFW4e6wifbU9LKVq7owM14bnE6ZbbYq3bn1jBP3Mw',
3560
+ width: 1168,
3561
+ height: 1168,
3562
+ format: 'png',
3563
+ },
3564
+ },
3565
+ ],
3566
+ faucets: ['https://docs.immutable.com/docs/zkEVM/guides/faucet'],
3567
+ icon: {
3568
+ url: 'ipfs://QmXFUYFW4e6wifbU9LKVq7owM14bnE6ZbbYq3bn1jBP3Mw',
3569
+ width: 1168,
3570
+ height: 1168,
3571
+ format: 'png',
3572
+ },
3573
+ infoURL: 'https://www.immutable.com',
3574
+ name: 'Immutable zkEVM',
3575
+ nativeCurrency: {
3576
+ name: 'IMX',
3577
+ symbol: 'IMX',
3578
+ decimals: 18,
3579
+ },
3580
+ networkId: 13371,
3581
+ rpc: [
3582
+ 'https://rpc.immutable.com',
3583
+ 'https://immutable-zkevm.drpc.org',
3584
+ 'wss://immutable-zkevm.drpc.org',
3585
+ ],
3586
+ shortName: 'imx',
3587
+ slug: 'immutable-zkevm',
3588
+ testnet: false,
3589
+ };
3590
+
3591
+ const chain$a = {
3592
+ chain: 'ETH',
3593
+ chainId: 421614,
3594
+ explorers: [
3595
+ {
3596
+ name: 'Arbitrum Sepolia Rollup Testnet Explorer',
3597
+ url: 'https://sepolia-explorer.arbitrum.io',
3598
+ standard: 'EIP3091',
3599
+ },
3600
+ ],
3601
+ faucets: [],
3602
+ infoURL: 'https://arbitrum.io',
3603
+ name: 'Arbitrum Sepolia',
3604
+ nativeCurrency: {
3605
+ name: 'Sepolia Ether',
3606
+ symbol: 'ETH',
3607
+ decimals: 18,
3608
+ },
3609
+ networkId: 421614,
3610
+ parent: {
3611
+ type: 'L2',
3612
+ chain: 'eip155-11155111',
3613
+ bridges: [
3614
+ {
3615
+ url: 'https://bridge.arbitrum.io',
3616
+ },
3617
+ ],
3618
+ },
3619
+ rpc: [
3620
+ 'https://sepolia-rollup.arbitrum.io/rpc',
3621
+ ],
3622
+ shortName: 'arb-sep',
3623
+ slug: 'arbitrum-sepolia',
3624
+ testnet: true,
3625
+ title: 'Arbitrum Sepolia Rollup Testnet',
3626
+ };
3627
+
3628
+ const chain$9 = {
3629
+ chain: 'ETH',
3630
+ chainId: 42161,
3631
+ explorers: [
3632
+ {
3633
+ name: 'Arbiscan',
3634
+ url: 'https://arbiscan.io',
3635
+ standard: 'EIP3091',
3636
+ },
3637
+ {
3638
+ name: 'Arbitrum Explorer',
3639
+ url: 'https://explorer.arbitrum.io',
3640
+ standard: 'EIP3091',
3641
+ },
3642
+ {
3643
+ name: 'dexguru',
3644
+ url: 'https://arbitrum.dex.guru',
3645
+ standard: 'EIP3091',
3646
+ icon: {
3647
+ url: 'ipfs://QmRaASKRSjQ5btoUQ2rNTJNxKtx2a2RoewgA7DMQkLVEne',
3648
+ width: 83,
3649
+ height: 82,
3650
+ format: 'svg',
3651
+ },
3652
+ },
3653
+ ],
3654
+ faucets: [],
3655
+ features: [],
3656
+ icon: {
3657
+ url: 'ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/arbitrum/512.png',
3658
+ width: 512,
3659
+ height: 512,
3660
+ format: 'png',
3661
+ },
3662
+ infoURL: 'https://arbitrum.io',
3663
+ name: 'Arbitrum One',
3664
+ nativeCurrency: {
3665
+ name: 'Ether',
3666
+ symbol: 'ETH',
3667
+ decimals: 18,
3668
+ },
3669
+ networkId: 42161,
3670
+ parent: {
3671
+ type: 'L2',
3672
+ chain: 'eip155-1',
3673
+ bridges: [
3674
+ {
3675
+ url: 'https://bridge.arbitrum.io',
3676
+ },
3677
+ ],
3678
+ },
3679
+ redFlags: [],
3680
+ rpc: [
3681
+ 'https://arb1.arbitrum.io/rpc',
3682
+ 'https://arbitrum-one.publicnode.com',
3683
+ 'wss://arbitrum-one.publicnode.com',
3684
+ ],
3685
+ shortName: 'arb1',
3686
+ slug: 'arbitrum',
3687
+ testnet: false,
3688
+ };
3689
+
3690
+ const chain$8 = {
3691
+ chain: 'ETH',
3692
+ chainId: 42170,
3693
+ explorers: [
3694
+ {
3695
+ name: 'Arbitrum Nova Chain Explorer',
3696
+ url: 'https://nova-explorer.arbitrum.io',
3697
+ standard: 'EIP3091',
3698
+ icon: {
3699
+ url: 'ipfs://QmYtUimyqHkkFxYdbXXRbUqNg2VLPUg6Uu2C2nmFWowiZM',
3700
+ width: 551,
3701
+ height: 540,
3702
+ format: 'png',
3703
+ },
3704
+ },
3705
+ {
3706
+ name: 'dexguru',
3707
+ url: 'https://nova.dex.guru',
3708
+ standard: 'EIP3091',
3709
+ icon: {
3710
+ url: 'ipfs://QmRaASKRSjQ5btoUQ2rNTJNxKtx2a2RoewgA7DMQkLVEne',
3711
+ width: 83,
3712
+ height: 82,
3713
+ format: 'svg',
3714
+ },
3715
+ },
3716
+ ],
3717
+ faucets: [],
3718
+ infoURL: 'https://arbitrum.io',
3719
+ name: 'Arbitrum Nova',
3720
+ nativeCurrency: {
3721
+ name: 'Ether',
3722
+ symbol: 'ETH',
3723
+ decimals: 18,
3724
+ },
3725
+ networkId: 42170,
3726
+ parent: {
3727
+ type: 'L2',
3728
+ chain: 'eip155-1',
3729
+ bridges: [
3730
+ {
3731
+ url: 'https://bridge.arbitrum.io',
3732
+ },
3733
+ ],
3734
+ },
3735
+ rpc: [
3736
+ 'https://nova.arbitrum.io/rpc',
3737
+ 'https://arbitrum-nova.publicnode.com',
3738
+ 'wss://arbitrum-nova.publicnode.com',
3739
+ ],
3740
+ shortName: 'arb-nova',
3741
+ slug: 'arbitrum-nova',
3742
+ testnet: false,
3743
+ };
3744
+
3745
+ const chain$7 = {
3746
+ chain: 'Polygon',
3747
+ chainId: 137,
3748
+ explorers: [
3749
+ {
3750
+ name: 'polygonscan',
3751
+ url: 'https://polygonscan.com',
3752
+ standard: 'EIP3091',
3753
+ },
3754
+ {
3755
+ name: 'dexguru',
3756
+ url: 'https://polygon.dex.guru',
3757
+ standard: 'EIP3091',
3758
+ icon: {
3759
+ url: 'ipfs://QmRaASKRSjQ5btoUQ2rNTJNxKtx2a2RoewgA7DMQkLVEne',
3760
+ width: 83,
3761
+ height: 82,
3762
+ format: 'svg',
3763
+ },
3764
+ },
3765
+ ],
3766
+ faucets: [],
3767
+ features: [],
3768
+ icon: {
3769
+ url: 'ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/polygon/512.png',
3770
+ width: 512,
3771
+ height: 512,
3772
+ format: 'png',
3773
+ },
3774
+ infoURL: 'https://polygon.technology/',
3775
+ name: 'Polygon Mainnet',
3776
+ nativeCurrency: {
3777
+ name: 'MATIC',
3778
+ symbol: 'MATIC',
3779
+ decimals: 18,
3780
+ },
3781
+ networkId: 137,
3782
+ redFlags: [],
3783
+ rpc: [
3784
+ 'https://polygon-rpc.com',
3785
+ 'https://rpc-mainnet.matic.network',
3786
+ 'https://matic-mainnet.chainstacklabs.com',
3787
+ 'https://rpc-mainnet.maticvigil.com',
3788
+ 'https://rpc-mainnet.matic.quiknode.pro',
3789
+ 'https://matic-mainnet-full-rpc.bwarelabs.com',
3790
+ 'https://polygon-bor.publicnode.com',
3791
+ 'wss://polygon-bor.publicnode.com',
3792
+ 'https://polygon.gateway.tenderly.co',
3793
+ 'wss://polygon.gateway.tenderly.co',
3794
+ ],
3795
+ shortName: 'matic',
3796
+ slip44: 966,
3797
+ slug: 'polygon',
3798
+ testnet: false,
3799
+ };
3800
+
3801
+ const chain$6 = {
3802
+ chain: 'Polygon',
3803
+ chainId: 80002,
3804
+ explorers: [
3805
+ {
3806
+ name: 'polygonamoy',
3807
+ url: 'https://www.oklink.com/amoy',
3808
+ standard: 'EIP3091',
3809
+ },
3810
+ ],
3811
+ faucets: ['https://faucet.polygon.technology/'],
3812
+ features: [],
3813
+ icon: {
3814
+ url: 'ipfs://QmcxZHpyJa8T4i63xqjPYrZ6tKrt55tZJpbXcjSDKuKaf9/polygon/512.png',
3815
+ width: 512,
3816
+ height: 512,
3817
+ format: 'png',
3818
+ },
3819
+ infoURL: 'https://polygon.technology/',
3820
+ name: 'Polygon Amoy Testnet',
3821
+ nativeCurrency: {
3822
+ name: 'MATIC',
3823
+ symbol: 'MATIC',
3824
+ decimals: 18,
3825
+ },
3826
+ networkId: 80002,
3827
+ redFlags: [],
3828
+ rpc: [
3829
+ 'https://rpc-amoy.polygon.technology',
3830
+ ],
3831
+ shortName: 'polygonamoy',
3832
+ slip44: 1,
3833
+ slug: 'polygon-amoy-testnet',
3834
+ testnet: true,
3835
+ title: 'Polygon Amoy Testnet',
3836
+ };
3837
+
3838
+ const chain$5 = {
3839
+ chain: 'Ancient8',
3840
+ chainId: 28122024,
3841
+ explorers: [
3842
+ {
3843
+ name: 'scan-testnet',
3844
+ url: 'https://scanv2-testnet.ancient8.gg',
3845
+ standard: 'EIP3091',
3846
+ },
3847
+ ],
3848
+ faucets: [],
3849
+ icon: {
3850
+ url: 'ipfs://bafkreievnqg3xjokaty4kfbxxbrzm5v5y7exbaaia2txrh4sfgrqsalfym',
3851
+ width: 128,
3852
+ height: 128,
3853
+ format: 'png',
3854
+ },
3855
+ infoURL: 'https://ancient8.gg/',
3856
+ name: 'Ancient8 Testnet',
3857
+ nativeCurrency: {
3858
+ name: 'Ether',
3859
+ symbol: 'ETH',
3860
+ decimals: 18,
3861
+ },
3862
+ networkId: 28122024,
3863
+ rpc: ['https://rpcv2-testnet.ancient8.gg'],
3864
+ shortName: 'a8',
3865
+ slip44: 1,
3866
+ slug: 'ancient8-testnet',
3867
+ testnet: true,
3868
+ };
3869
+
3870
+ const chain$4 = {
3871
+ chain: 'Ancient8',
3872
+ chainId: 888888888,
3873
+ explorers: [
3874
+ {
3875
+ name: 'Ancient8 Explorer',
3876
+ url: 'https://scan.ancient8.gg',
3877
+ standard: 'EIP3091',
3878
+ },
3879
+ ],
3880
+ faucets: [],
3881
+ icon: {
3882
+ url: 'ipfs://bafkreievnqg3xjokaty4kfbxxbrzm5v5y7exbaaia2txrh4sfgrqsalfym',
3883
+ width: 128,
3884
+ height: 128,
3885
+ format: 'png',
3886
+ },
3887
+ infoURL: 'https://ancient8.gg/',
3888
+ name: 'Ancient8',
3889
+ nativeCurrency: {
3890
+ name: 'Ether',
3891
+ symbol: 'ETH',
3892
+ decimals: 18,
3893
+ },
3894
+ networkId: 888888888,
3895
+ rpc: ['https://rpc.ancient8.gg'],
3896
+ shortName: 'ancient8',
3897
+ slug: 'ancient8',
3898
+ testnet: false,
3899
+ };
3900
+
3901
+ const chain$3 = {
3902
+ chain: 'ETH',
3903
+ chainId: 999999999,
3904
+ explorers: [
3905
+ {
3906
+ name: 'Zora Sepolia Testnet Network Explorer',
3907
+ url: 'https://sepolia.explorer.zora.energy',
3908
+ standard: 'EIP3091',
3909
+ },
3910
+ ],
3911
+ faucets: [],
3912
+ icon: {
3913
+ url: 'ipfs://bafkreifvrly5tgd34xqeo67s4etmiu52bkroml7uy7eosizf57htf5nrzq',
3914
+ width: 250,
3915
+ height: 250,
3916
+ format: 'png',
3917
+ },
3918
+ infoURL: 'https://zora.energy',
3919
+ name: 'Zora Sepolia Testnet',
3920
+ nativeCurrency: {
3921
+ name: 'Sepolia Ether',
3922
+ symbol: 'ETH',
3923
+ decimals: 18,
3924
+ },
3925
+ networkId: 999999999,
3926
+ rpc: ['https://sepolia.rpc.zora.energy'],
3927
+ shortName: 'zsep',
3928
+ slip44: 1,
3929
+ slug: 'zora-sepolia-testnet',
3930
+ testnet: true,
3931
+ };
3932
+
3933
+ const chain$2 = {
3934
+ chain: 'ETH',
3935
+ chainId: 7777777,
3936
+ explorers: [
3937
+ {
3938
+ name: 'Zora Network Explorer',
3939
+ url: 'https://explorer.zora.energy',
3940
+ standard: 'EIP3091',
3941
+ },
3942
+ ],
3943
+ faucets: [],
3944
+ features: [],
3945
+ icon: {
3946
+ url: 'ipfs://QmZ6qaRwTPFEZUspwMUjaxC6KhmzcELdRQcQzS3P72Dzts/Vector.svg',
3947
+ width: 512,
3948
+ height: 512,
3949
+ format: 'svg',
3950
+ },
3951
+ infoURL: 'https://zora.energy',
3952
+ name: 'Zora',
3953
+ nativeCurrency: {
3954
+ name: 'Ether',
3955
+ symbol: 'ETH',
3956
+ decimals: 18,
3957
+ },
3958
+ networkId: 7777777,
3959
+ redFlags: [],
3960
+ rpc: ['https://rpc.zora.energy/'],
3961
+ shortName: 'zora',
3962
+ slug: 'zora',
3963
+ testnet: false,
3964
+ };
3965
+
3966
+ const chain$1 = {
3967
+ chain: 'Degen',
3968
+ chainId: 666666666,
3969
+ explorers: [],
3970
+ faucets: [],
3971
+ icon: {
3972
+ url: 'ipfs://Qmb6yAe4wXeBkxjfhxzoUT9TzETcmE7Vne59etm9GJaQf7',
3973
+ width: 789,
3974
+ height: 668,
3975
+ format: 'svg',
3976
+ },
3977
+ infoURL: 'https://degen.tips',
3978
+ name: 'Degen Chain',
3979
+ nativeCurrency: {
3980
+ name: 'DEGEN',
3981
+ symbol: 'DEGEN',
3982
+ decimals: 18,
3983
+ },
3984
+ networkId: 666666666,
3985
+ rpc: ['https://rpc.degen.tips'],
3986
+ shortName: 'degen-chain',
3987
+ slug: 'degen-chain',
3988
+ status: 'incubating',
3989
+ testnet: false,
3990
+ title: 'Degen Chain',
3991
+ };
3992
+
3993
+ const chain = {
3994
+ chain: 'Immutable zkEVM',
3995
+ chainId: 13473,
3996
+ explorers: [
3997
+ {
3998
+ name: 'Immutable Testnet explorer',
3999
+ url: 'https://explorer.testnet.immutable.com',
4000
+ standard: 'EIP3091',
4001
+ icon: {
4002
+ url: 'ipfs://QmXFUYFW4e6wifbU9LKVq7owM14bnE6ZbbYq3bn1jBP3Mw',
4003
+ width: 1168,
4004
+ height: 1168,
4005
+ format: 'png',
4006
+ },
4007
+ },
4008
+ ],
4009
+ faucets: ['https://docs.immutable.com/docs/zkEVM/guides/faucet'],
4010
+ icon: {
4011
+ url: 'ipfs://QmXFUYFW4e6wifbU9LKVq7owM14bnE6ZbbYq3bn1jBP3Mw',
4012
+ width: 1168,
4013
+ height: 1168,
4014
+ format: 'png',
4015
+ },
4016
+ infoURL: 'https://www.immutable.com',
4017
+ name: 'Immutable zkEVM Testnet',
4018
+ nativeCurrency: {
4019
+ name: 'Test IMX',
4020
+ symbol: 'tIMX',
4021
+ decimals: 18,
4022
+ },
4023
+ networkId: 13473,
4024
+ rpc: [
4025
+ 'https://rpc.testnet.immutable.com',
4026
+ 'https://immutable-zkevm-testnet.drpc.org',
4027
+ 'wss://immutable-zkevm-testnet.drpc.org',
4028
+ ],
4029
+ shortName: 'imx-testnet',
4030
+ slip44: 1,
4031
+ slug: 'immutable-zkevm-testnet',
4032
+ testnet: true,
4033
+ };
4034
+
4035
+ const chainMap = {
4036
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4037
+ 56: chain$m,
4038
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4039
+ 97: chain$l,
4040
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4041
+ 8453: chain$k,
4042
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4043
+ 84532: chain$j,
4044
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4045
+ 4337: chain$i,
4046
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4047
+ 13337: chain$h,
4048
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4049
+ 43113: chain$g,
4050
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4051
+ 43114: chain$f,
4052
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4053
+ 11155111: chain$e,
4054
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4055
+ 59140: chain$d,
4056
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4057
+ 10200: chain$c,
4058
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4059
+ 421614: chain$a,
4060
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4061
+ 42161: chain$9,
4062
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4063
+ 42170: chain$8,
4064
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4065
+ 137: chain$7,
4066
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4067
+ 80002: chain$6,
4068
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4069
+ 28122024: chain$5,
4070
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4071
+ 888888888: chain$4,
4072
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4073
+ 999999999: chain$3,
4074
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4075
+ 7777777: chain$2,
4076
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4077
+ 666666666: chain$1,
4078
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4079
+ 13473: chain,
4080
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4081
+ 13371: chain$b,
4082
+ };
4083
+
4084
+ var BackendTransactionStatus;
4085
+ (function (BackendTransactionStatus) {
4086
+ BackendTransactionStatus["PENDING"] = "PENDING";
4087
+ BackendTransactionStatus["SUBMITTED"] = "SUBMITTED";
4088
+ BackendTransactionStatus["SUCCESSFUL"] = "SUCCESSFUL";
4089
+ BackendTransactionStatus["REVERTED"] = "REVERTED";
4090
+ BackendTransactionStatus["FAILED"] = "FAILED";
4091
+ BackendTransactionStatus["CANCELLED"] = "CANCELLED";
4092
+ })(BackendTransactionStatus || (BackendTransactionStatus = {}));
4093
+ var ProviderEvent;
4094
+ (function (ProviderEvent) {
4095
+ ProviderEvent["ACCOUNTS_CHANGED"] = "accountsChanged";
4096
+ })(ProviderEvent || (ProviderEvent = {}));
4097
+
4098
+ class TypedEventEmitter {
4099
+ emitter = new events.EventEmitter();
4100
+ emit(eventName, ...eventArg) {
4101
+ this.emitter.emit(eventName, ...eventArg);
4102
+ }
4103
+ on(eventName, handler) {
4104
+ this.emitter.on(eventName, handler);
4105
+ }
4106
+ removeListener(eventName, handler) {
4107
+ this.emitter.removeListener(eventName, handler);
4108
+ }
4109
+ }
4110
+
4111
+ /**
4112
+ * ProviderErrors should take priority over RpcErrorCodes
4113
+ * https://eips.ethereum.org/EIPS/eip-1193#provider-errors
4114
+ * https://eips.ethereum.org/EIPS/eip-1474#error-codes
4115
+ */
4116
+ var ProviderErrorCode;
4117
+ (function (ProviderErrorCode) {
4118
+ ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
4119
+ ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
4120
+ ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
4121
+ ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
4122
+ })(ProviderErrorCode || (ProviderErrorCode = {}));
4123
+ var RpcErrorCode;
4124
+ (function (RpcErrorCode) {
4125
+ RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
4126
+ RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
4127
+ RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
4128
+ RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
4129
+ RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
4130
+ RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
4131
+ RpcErrorCode[RpcErrorCode["TRANSACTION_REJECTED"] = -32003] = "TRANSACTION_REJECTED";
4132
+ })(RpcErrorCode || (RpcErrorCode = {}));
4133
+ class JsonRpcError extends Error {
4134
+ message;
4135
+ code;
4136
+ constructor(code, message) {
4137
+ super(message);
4138
+ this.message = message;
4139
+ this.code = code;
4140
+ }
4141
+ }
4142
+
4143
+ const buildOpenfortTransactions = async (transactionRequest, backendApiClients, instanceManager, policyId) => {
4144
+ const interactions = transactionRequest.map((tx) => {
4145
+ if (!tx.to) {
4146
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
4147
+ }
4148
+ return {
4149
+ to: String(tx.to),
4150
+ data: tx.data ? String(tx.data) : undefined,
4151
+ value: tx.value ? String(tx.value) : undefined,
4152
+ };
4153
+ });
4154
+ const accessToken = instanceManager.getAccessToken();
4155
+ const chainId = instanceManager.getChainID();
4156
+ if (!accessToken || !chainId) {
4157
+ throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'No access token found');
4158
+ }
4159
+ const transactionResponse = await backendApiClients.transactionIntentsApi.createTransactionIntent({
4160
+ createTransactionIntentRequest: {
4161
+ policy: policyId,
4162
+ chainId: Number(chainId),
4163
+ interactions,
4164
+ },
4165
+ }, {
4166
+ headers: {
4167
+ authorization: `Bearer ${backendApiClients.config.backend.accessToken}`,
4168
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4169
+ 'x-player-token': accessToken.token,
4170
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4171
+ 'x-auth-provider': accessToken.thirdPartyProvider,
4172
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4173
+ 'x-token-type': accessToken.thirdPartyTokenType,
4174
+ },
4175
+ });
4176
+ return transactionResponse.data;
4177
+ };
4178
+ const sendTransaction = async ({ params, signer, backendClient, instanceManager, policyId, }) => {
4179
+ const openfortTransaction = await buildOpenfortTransactions(params, backendClient, instanceManager, policyId);
4180
+ let response;
4181
+ if (openfortTransaction?.nextAction?.payload?.userOperationHash) {
4182
+ const signature = await signer.sign(openfortTransaction.nextAction.payload.userOperationHash);
4183
+ const openfortSignatureResponse = (await backendClient.transactionIntentsApi.signature({
4184
+ id: openfortTransaction.id,
4185
+ signatureRequest: { signature },
4186
+ })).data.response;
4187
+ if (!openfortSignatureResponse) {
4188
+ throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
4189
+ }
4190
+ response = openfortSignatureResponse;
4191
+ }
4192
+ else if (openfortTransaction.response) {
4193
+ response = openfortTransaction.response;
4194
+ }
4195
+ else {
4196
+ throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, 'Transaction failed to submit');
4197
+ }
4198
+ if (response.status === 0 && !response.transactionHash) {
4199
+ throw new JsonRpcError(RpcErrorCode.RPC_SERVER_ERROR, response.error.reason);
4200
+ }
4201
+ return response.transactionHash;
4202
+ };
4203
+
4204
+ const getSignedTypedData = async (typedData, accountType, chainId, signer, evmAddress) => {
4205
+ // Ethers auto-generates the EIP712Domain type in the TypedDataEncoder, and so it needs to be removed
4206
+ const types = { ...typedData.types };
4207
+ // @ts-ignore
4208
+ delete types.EIP712Domain;
4209
+ // Hash the EIP712 payload and generate the complete payload
4210
+ let typedDataHash = hash._TypedDataEncoder.hash(typedData.domain, types, typedData.message);
4211
+ if (accountType === AccountType.UPGRADEABLE_V5) {
4212
+ const updatedDomain = {
4213
+ name: 'Openfort',
4214
+ version: '0.5',
4215
+ chainId: Number(chainId),
4216
+ verifyingContract: evmAddress,
4217
+ };
4218
+ const updatedTypes = {
4219
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4220
+ OpenfortMessage: [{ name: 'hashedMessage', type: 'bytes32' }],
4221
+ };
4222
+ const updatedMessage = {
4223
+ hashedMessage: typedDataHash,
4224
+ };
4225
+ typedDataHash = hash._TypedDataEncoder.hash(updatedDomain, updatedTypes, updatedMessage);
4226
+ // primaryType: "OpenfortMessage"
4227
+ }
4228
+ const ethsigNoType = await signer.sign(typedDataHash, false, false);
4229
+ return ethsigNoType;
4230
+ };
4231
+
4232
+ const REQUIRED_TYPED_DATA_PROPERTIES = ['types', 'domain', 'primaryType', 'message'];
4233
+ const isValidTypedDataPayload = (typedData) => (REQUIRED_TYPED_DATA_PROPERTIES.every((key) => key in typedData));
4234
+ const transformTypedData = (typedData, chainId) => {
4235
+ let transformedTypedData;
4236
+ if (typeof typedData === 'string') {
4237
+ try {
4238
+ transformedTypedData = JSON.parse(typedData);
4239
+ }
4240
+ catch (err) {
4241
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Failed to parse typed data JSON: ${err}`);
4242
+ }
4243
+ }
4244
+ else if (typeof typedData === 'object') {
4245
+ transformedTypedData = typedData;
4246
+ }
4247
+ else {
4248
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Invalid typed data argument: ${typedData}`);
4249
+ }
4250
+ if (!isValidTypedDataPayload(transformedTypedData)) {
4251
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Invalid typed data argument. The following properties are required:
4252
+ ${REQUIRED_TYPED_DATA_PROPERTIES.join(', ')}`);
4253
+ }
4254
+ const providedChainId = transformedTypedData.domain?.chainId;
4255
+ if (providedChainId) {
4256
+ // domain.chainId (if defined) can be a number, string, or hex value, but the backend & guardian only accept a number.
4257
+ if (typeof providedChainId === 'string') {
4258
+ if (providedChainId.startsWith('0x')) {
4259
+ transformedTypedData.domain.chainId = parseInt(providedChainId, 16);
4260
+ }
4261
+ else {
4262
+ transformedTypedData.domain.chainId = parseInt(providedChainId, 10);
4263
+ }
4264
+ }
4265
+ if (transformedTypedData.domain.chainId !== chainId) {
4266
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Invalid chainId, expected ${chainId}`);
4267
+ }
4268
+ }
4269
+ return transformedTypedData;
4270
+ };
4271
+ const signTypedDataV4 = async ({ params, method, signer, accountType, rpcProvider, }) => {
4272
+ const fromAddress = params[0];
4273
+ const typedDataParam = params[1];
4274
+ if (!fromAddress || !typedDataParam) {
4275
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `${method} requires an address and a typed data JSON`);
4276
+ }
4277
+ const { chainId } = await rpcProvider.detectNetwork();
4278
+ const typedData = transformTypedData(typedDataParam, chainId);
4279
+ const signature = await getSignedTypedData(typedData, accountType, chainId, signer, fromAddress);
4280
+ return signature;
4281
+ };
4282
+
4283
+ class EvmProvider {
4284
+ #signer;
4285
+ #policyId;
4286
+ #eventEmitter;
4287
+ #rpcProvider; // Used for read
4288
+ #instanceManager;
4289
+ #backendApiClients;
4290
+ #address;
4291
+ isOpenfort = true;
4292
+ constructor({ signer, address, backendApiClients, instanceManager, openfortEventEmitter, policyId, }) {
4293
+ this.#signer = signer;
4294
+ this.#policyId = policyId;
4295
+ this.#address = address;
4296
+ this.#instanceManager = instanceManager;
4297
+ this.#backendApiClients = backendApiClients;
4298
+ const chainId = Number(this.#instanceManager.getChainID());
4299
+ this.#rpcProvider = new providers.StaticJsonRpcProvider(chainMap[chainId].rpc[0]);
4300
+ this.#backendApiClients = backendApiClients;
4301
+ this.#eventEmitter = new TypedEventEmitter();
4302
+ openfortEventEmitter.on(OpenfortEvents.LOGGED_OUT, this.#handleLogout);
4303
+ }
4304
+ #handleLogout = () => {
4305
+ const shouldEmitAccountsChanged = !!this.#address;
4306
+ this.#address = undefined;
4307
+ this.#signer.logout();
4308
+ if (shouldEmitAccountsChanged) {
4309
+ this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
4310
+ }
4311
+ };
4312
+ async #performRequest(request) {
4313
+ switch (request.method) {
4314
+ case 'eth_requestAccounts': {
4315
+ if (this.#address) {
4316
+ return [this.#address];
4317
+ }
4318
+ const user = await this.#signer.ensureEmbeddedAccount();
4319
+ this.#address = user.address;
4320
+ this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.#address]);
4321
+ return [this.#address];
4322
+ }
4323
+ case 'eth_sendTransaction': {
4324
+ if (!this.#address) {
4325
+ throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorized - call eth_requestAccounts first');
4326
+ }
4327
+ return await sendTransaction({
4328
+ params: request.params || [],
4329
+ signer: this.#signer,
4330
+ backendClient: this.#backendApiClients,
4331
+ instanceManager: this.#instanceManager,
4332
+ policyId: this.#policyId,
4333
+ });
4334
+ }
4335
+ case 'eth_accounts': {
4336
+ return this.#address ? [this.#address] : [];
4337
+ }
4338
+ case 'eth_signTypedData':
4339
+ case 'eth_signTypedData_v4': {
4340
+ if (!this.#address) {
4341
+ throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorized - call eth_requestAccounts first');
4342
+ }
4343
+ const accountType = this.#instanceManager.getAccountType();
4344
+ if (!accountType) {
4345
+ throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorized - call eth_requestAccounts first');
4346
+ }
4347
+ return await signTypedDataV4({
4348
+ method: request.method,
4349
+ params: request.params || [],
4350
+ signer: this.#signer,
4351
+ accountType,
4352
+ rpcProvider: this.#rpcProvider,
4353
+ });
4354
+ }
4355
+ case 'eth_chainId': {
4356
+ // Call detect network to fetch the chainId so to take advantage of
4357
+ // the caching layer provided by StaticJsonRpcProvider.
4358
+ // In case Openfort is changed from StaticJsonRpcProvider to a
4359
+ // JsonRpcProvider, this function will still work as expected given
4360
+ // that detectNetwork call _uncachedDetectNetwork which will force
4361
+ // the provider to re-fetch the chainId from remote.
4362
+ const { chainId } = await this.#rpcProvider.detectNetwork();
4363
+ return bytes.hexlify(chainId);
4364
+ }
4365
+ // Pass through methods
4366
+ case 'eth_gasPrice':
4367
+ case 'eth_getBalance':
4368
+ case 'eth_getCode':
4369
+ case 'eth_getStorageAt':
4370
+ case 'eth_estimateGas':
4371
+ case 'eth_call':
4372
+ case 'eth_blockNumber':
4373
+ case 'eth_getBlockByHash':
4374
+ case 'eth_getBlockByNumber':
4375
+ case 'eth_getTransactionByHash':
4376
+ case 'eth_getTransactionReceipt':
4377
+ case 'eth_getTransactionCount': {
4378
+ return this.#rpcProvider.send(request.method, request.params || []);
4379
+ }
4380
+ default: {
4381
+ throw new JsonRpcError(ProviderErrorCode.UNSUPPORTED_METHOD, 'Method not supported');
4382
+ }
4383
+ }
4384
+ }
4385
+ async #performJsonRpcRequest(request) {
4386
+ const { id, jsonrpc } = request;
4387
+ try {
4388
+ const result = await this.#performRequest(request);
4389
+ return {
4390
+ id,
4391
+ jsonrpc,
4392
+ result,
4393
+ };
4394
+ }
4395
+ catch (error) {
4396
+ let jsonRpcError;
4397
+ if (error instanceof JsonRpcError) {
4398
+ jsonRpcError = error;
4399
+ }
4400
+ else if (error instanceof Error) {
4401
+ jsonRpcError = new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, error.message);
4402
+ }
4403
+ else {
4404
+ jsonRpcError = new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Internal error');
4405
+ }
4406
+ return {
4407
+ id,
4408
+ jsonrpc,
4409
+ error: jsonRpcError,
4410
+ };
4411
+ }
4412
+ }
4413
+ async request(request) {
4414
+ try {
4415
+ return this.#performRequest(request);
4416
+ }
4417
+ catch (error) {
4418
+ if (error instanceof JsonRpcError) {
4419
+ throw error;
4420
+ }
4421
+ if (error instanceof Error) {
4422
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, error.message);
4423
+ }
4424
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Internal error');
4425
+ }
4426
+ }
4427
+ sendAsync(request, callback) {
4428
+ if (!callback) {
4429
+ throw new Error('No callback provided');
4430
+ }
4431
+ if (Array.isArray(request)) {
4432
+ Promise.all(request.map(this.#performJsonRpcRequest)).then((result) => {
4433
+ callback(null, result);
4434
+ }).catch((error) => {
4435
+ callback(error, []);
4436
+ });
4437
+ }
4438
+ else {
4439
+ this.#performJsonRpcRequest(request).then((result) => {
4440
+ callback(null, result);
4441
+ }).catch((error) => {
4442
+ callback(error, null);
4443
+ });
4444
+ }
4445
+ }
4446
+ async send(request, callbackOrParams, callback) {
4447
+ // Web3 >= 1.0.0-beta.38 calls `send` with method and parameters.
4448
+ if (typeof request === 'string') {
4449
+ if (typeof callbackOrParams === 'function') {
4450
+ return this.sendAsync({
4451
+ method: request,
4452
+ params: [],
4453
+ }, callbackOrParams);
4454
+ }
4455
+ if (callback) {
4456
+ return this.sendAsync({
4457
+ method: request,
4458
+ params: Array.isArray(callbackOrParams) ? callbackOrParams : [],
4459
+ }, callback);
4460
+ }
4461
+ return this.request({
4462
+ method: request,
4463
+ params: Array.isArray(callbackOrParams) ? callbackOrParams : [],
4464
+ });
4465
+ }
4466
+ // Web3 <= 1.0.0-beta.37 uses `send` with a callback for async queries.
4467
+ if (typeof callbackOrParams === 'function') {
4468
+ return this.sendAsync(request, callbackOrParams);
4469
+ }
4470
+ if (!Array.isArray(request) && typeof request === 'object') {
4471
+ return this.#performJsonRpcRequest(request);
4472
+ }
4473
+ throw new JsonRpcError(RpcErrorCode.INVALID_REQUEST, 'Invalid request');
4474
+ }
4475
+ on(event, listener) {
4476
+ this.#eventEmitter.on(event, listener);
4477
+ }
4478
+ removeListener(event, listener) {
4479
+ this.#eventEmitter.removeListener(event, listener);
4480
+ }
4481
+ }
4482
+
4483
+ const openfortProviderInfo = {
4484
+ // eslint-disable-next-line max-len
4485
+ icon: 'data:image/svg+xml,<svg aria-hidden="true" viewBox="597.32 331.34 171.36 105.32" ><g><rect x="673.9" y="404.26" width="18.2" height="32.4" /><polygon points="768.68,331.36 768.68,331.36 768.68,331.34 610.78,331.34 610.78,331.36 597.32,331.36 597.32,436.64 615.52,436.64 615.52,349.54 750.48,349.54 750.48,436.64 768.68,436.64 " /><polygon points="732.16,367.79 633.83,367.79 633.83,370.19 633.79,370.19 633.79,436.64 651.99,436.64 651.99,385.99 713.9,385.99 713.9,436.64 732.09,436.64 732.09,385.99 732.16,385.99 " /></g></svg>',
4486
+ name: 'Ecosystem ID',
4487
+ rdns: 'com.ecosystem.id',
4488
+ uuid: uuid.v4(),
4489
+ };
4490
+ function announceProvider(detail) {
4491
+ if (typeof window === 'undefined')
4492
+ return;
4493
+ const event = new CustomEvent('eip6963:announceProvider', { detail: Object.freeze(detail) });
4494
+ window.dispatchEvent(event);
4495
+ const handler = () => window.dispatchEvent(event);
4496
+ window.addEventListener('eip6963:requestProvider', handler);
4497
+ }
4498
+
3052
4499
  var SignerType;
3053
4500
  (function (SignerType) {
3054
4501
  SignerType["EMBEDDED"] = "embedded";
@@ -3254,7 +4701,7 @@ class AuthManager {
3254
4701
  headers: {
3255
4702
  authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
3256
4703
  // eslint-disable-next-line @typescript-eslint/naming-convention
3257
- 'player-token': accessToken,
4704
+ 'x-player-token': accessToken,
3258
4705
  },
3259
4706
  });
3260
4707
  }
@@ -4073,6 +5520,13 @@ class NotLoggedIn extends Error {
4073
5520
  Object.setPrototypeOf(this, NotLoggedIn.prototype);
4074
5521
  }
4075
5522
  }
5523
+ class EmbeddedNotConfigured extends Error {
5524
+ constructor(message) {
5525
+ super(message);
5526
+ this.name = 'EmbeddedNotConfigured';
5527
+ Object.setPrototypeOf(this, EmbeddedNotConfigured.prototype);
5528
+ }
5529
+ }
4076
5530
  class NoSignerConfigured extends Error {
4077
5531
  constructor(message) {
4078
5532
  super(message);
@@ -4094,11 +5548,13 @@ class Openfort {
4094
5548
  instanceManager;
4095
5549
  backendApiClients;
4096
5550
  iframeManager;
5551
+ openfortEventEmitter;
4097
5552
  constructor(sdkConfiguration) {
4098
5553
  this.config = new SDKConfiguration(sdkConfiguration);
4099
5554
  this.backendApiClients = new BackendApiClients(this.config.openfortAPIConfig);
4100
5555
  this.authManager = new AuthManager(this.config, this.backendApiClients);
4101
5556
  this.instanceManager = new InstanceManager(new SessionStorage(), new LocalStorage(), new LocalStorage(), this.authManager);
5557
+ this.openfortEventEmitter = new TypedEventEmitter();
4102
5558
  this.iframeManager = new IframeManager(this.config);
4103
5559
  }
4104
5560
  async logout() {
@@ -4130,6 +5586,29 @@ class Openfort {
4130
5586
  this.instanceManager.removeJWK();
4131
5587
  }
4132
5588
  }
5589
+ getEthereumProvider(options = {
5590
+ announceProvider: true,
5591
+ }) {
5592
+ if (!(this.signer instanceof EmbeddedSigner)) {
5593
+ throw new EmbeddedNotConfigured('Embedded signer must be configured to get Ethereum provider');
5594
+ }
5595
+ const address = this.instanceManager.getAccountAddress();
5596
+ const provider = new EvmProvider({
5597
+ openfortEventEmitter: this.openfortEventEmitter,
5598
+ signer: this.signer,
5599
+ address: address,
5600
+ instanceManager: this.instanceManager,
5601
+ backendApiClients: this.backendApiClients,
5602
+ policyId: options.policy,
5603
+ });
5604
+ if (options?.announceProvider) {
5605
+ announceProvider({
5606
+ info: openfortProviderInfo,
5607
+ provider,
5608
+ });
5609
+ }
5610
+ return provider;
5611
+ }
4133
5612
  async flushSigner() {
4134
5613
  if (this.signer) {
4135
5614
  await this.signer.logout();