diff --git a/example-dimo-auth/dimo-network-login-with-dimo-0.0.8.tgz b/example-dimo-auth/dimo-network-login-with-dimo-0.0.8.tgz index 5ec2484..a3928b4 100644 Binary files a/example-dimo-auth/dimo-network-login-with-dimo-0.0.8.tgz and b/example-dimo-auth/dimo-network-login-with-dimo-0.0.8.tgz differ diff --git a/example-dimo-auth/dimo-network-login-with-dimo-0.0.9.tgz b/example-dimo-auth/dimo-network-login-with-dimo-0.0.9.tgz new file mode 100644 index 0000000..33d1c0d Binary files /dev/null and b/example-dimo-auth/dimo-network-login-with-dimo-0.0.9.tgz differ diff --git a/example-dimo-auth/package-lock.json b/example-dimo-auth/package-lock.json index fdbf1e5..4de133b 100644 --- a/example-dimo-auth/package-lock.json +++ b/example-dimo-auth/package-lock.json @@ -8,7 +8,7 @@ "name": "example-dimo-auth", "version": "0.1.0", "dependencies": { - "@dimo-network/login-with-dimo": "file:./dimo-network-login-with-dimo-0.0.8.tgz", + "@dimo-network/login-with-dimo": "file:./dimo-network-login-with-dimo-0.0.9.tgz", "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", @@ -2235,9 +2235,9 @@ } }, "node_modules/@dimo-network/login-with-dimo": { - "version": "0.0.8", - "resolved": "file:dimo-network-login-with-dimo-0.0.8.tgz", - "integrity": "sha512-vPUXzWu5+4buQP8lRuRONMg+hi6NBLxUxecu4D+Mpqv1KFEx9srH+qfu9YtuRaCU/gnlhPk2UcBH9ROuHqfkzA==", + "version": "0.0.9", + "resolved": "file:dimo-network-login-with-dimo-0.0.9.tgz", + "integrity": "sha512-F2xCQOcB+QkMIN/4gbSr88m9+k1kGfF6lBaDUjxcdAqyYMO0lCHVRBLwAl8J5e8jA4aIWHDerDhX+JWu6Roc1Q==", "license": "ISC", "peerDependencies": { "react": "^18.0.0", @@ -3489,9 +3489,9 @@ } }, "node_modules/@types/express-serve-static-core": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.0.1.tgz", - "integrity": "sha512-CRICJIl0N5cXDONAdlTv5ShATZ4HEwk6kDDIW2/w9qOWKg+NU/5F8wYRWCrONad0/UKkloNSmmyN/wX4rtpbVA==", + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.0.2.tgz", + "integrity": "sha512-vluaspfvWEtE4vcSDlKRNer52DvOGrB2xv6diXy6UKyKW0lqZiWHGNApSyxOv+8DE5Z27IzVvE7hNkxg7EXIcg==", "dependencies": { "@types/node": "*", "@types/qs": "*", @@ -3582,9 +3582,9 @@ "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==" }, "node_modules/@types/node": { - "version": "16.18.119", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.119.tgz", - "integrity": "sha512-ia7V9a2FnhUFfetng4/sRPBMTwHZUkPFY736rb1cg9AgG7MZdR97q7/nLR9om+sq5f1la9C857E0l/nrI0RiFQ==" + "version": "16.18.120", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.120.tgz", + "integrity": "sha512-Dmi4bhZ7CHyD4sv4awCZx9RBxWOXSejxTF6B5WQ5UzfLcyEg7JqdDDsjvdMRYES9EcTWHlHZe01PInSj18yP2A==" }, "node_modules/@types/node-forge": { "version": "1.3.11", @@ -5108,9 +5108,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001683", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001683.tgz", - "integrity": "sha512-iqmNnThZ0n70mNwvxpEC2nBJ037ZHZUoBI5Gorh1Mw6IlEAZujEoU1tXA628iZfzm7R9FvFzxbfdgml82a3k8Q==", + "version": "1.0.30001684", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001684.tgz", + "integrity": "sha512-G1LRwLIQjBQoyq0ZJGqGIJUXzJ8irpbjHLpVRXDvBEScFJ9b17sgK6vlx0GAJFE21okD7zXl08rRRUfq6HdoEQ==", "funding": [ { "type": "opencollective", @@ -6374,9 +6374,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.64", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.64.tgz", - "integrity": "sha512-IXEuxU+5ClW2IGEYFC2T7szbyVgehupCWQe5GNh+H065CD6U6IFN0s4KeAMFGNmQolRU4IV7zGBWSYMmZ8uuqQ==" + "version": "1.5.65", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.65.tgz", + "integrity": "sha512-PWVzBjghx7/wop6n22vS2MLU8tKGd4Q91aCEGhG/TYmW6PP5OcSXcdnxTe1NNt0T66N8D6jxh4kC8UsdzOGaIw==" }, "node_modules/emittery": { "version": "0.8.1", @@ -6611,13 +6611,13 @@ } }, "node_modules/es-to-primitive": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", - "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.3.0.tgz", + "integrity": "sha512-w+5mJ3GuFL+NjVtJlvydShqE1eN3h3PbI7/5LAsYJP/2qtuMXjfL2LpHSRqo4b4eSF5K/DH1JXKUAHSB2UW50g==", "dependencies": { - "is-callable": "^1.1.4", - "is-date-object": "^1.0.1", - "is-symbol": "^1.0.2" + "is-callable": "^1.2.7", + "is-date-object": "^1.0.5", + "is-symbol": "^1.0.4" }, "engines": { "node": ">= 0.4" @@ -8765,11 +8765,14 @@ } }, "node_modules/is-finalizationregistry": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-finalizationregistry/-/is-finalizationregistry-1.0.2.tgz", - "integrity": "sha512-0by5vtUJs8iFQb5TYUHHPudOR+qXYIMKtiUzvLIZITZUjknFmziyBJuLhVRc+Ds0dREFlskDNJKYIdIzu/9pfw==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-finalizationregistry/-/is-finalizationregistry-1.1.0.tgz", + "integrity": "sha512-qfMdqbAQEwBw78ZyReKnlA8ezmPdb9BemzIIip/JkjaZUhitfXDkkr+3QTboW0JrSXT1QWyYShpvnNHGZ4c4yA==", "dependencies": { - "call-bind": "^1.0.2" + "call-bind": "^1.0.7" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -10649,9 +10652,9 @@ } }, "node_modules/nanoid": { - "version": "3.3.7", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", - "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", + "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==", "funding": [ { "type": "github", @@ -13016,17 +13019,17 @@ } }, "node_modules/reflect.getprototypeof": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.6.tgz", - "integrity": "sha512-fmfw4XgoDke3kdI6h4xcUz1dG8uaiv5q9gcEwLS4Pnth2kxT+GZ7YehS1JTMGBQmtV7Y4GFGbs2re2NqhdozUg==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.7.tgz", + "integrity": "sha512-bMvFGIUKlc/eSfXNX+aZ+EL95/EgZzuwA0OBPTbZZDEJw/0AkentjMuM1oiRfwHrshqk4RzdgiTg5CcDalXN5g==", "dependencies": { "call-bind": "^1.0.7", "define-properties": "^1.2.1", - "es-abstract": "^1.23.1", + "es-abstract": "^1.23.5", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.4", - "globalthis": "^1.0.3", - "which-builtin-type": "^1.1.3" + "gopd": "^1.0.1", + "which-builtin-type": "^1.1.4" }, "engines": { "node": ">= 0.4" @@ -14983,16 +14986,17 @@ } }, "node_modules/typed-array-byte-offset": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/typed-array-byte-offset/-/typed-array-byte-offset-1.0.2.tgz", - "integrity": "sha512-Ous0vodHa56FviZucS2E63zkgtgrACj7omjwd/8lTEMEPFFyjfixMZ1ZXenpgCFBBt4EC1J2XsyVS2gkG0eTFA==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/typed-array-byte-offset/-/typed-array-byte-offset-1.0.3.tgz", + "integrity": "sha512-GsvTyUHTriq6o/bHcTd0vM7OQ9JEdlvluu9YISaA7+KzDzPaIzEeDFNkTfhdE3MYcNhNi0vq/LlegYgIs5yPAw==", "dependencies": { "available-typed-arrays": "^1.0.7", "call-bind": "^1.0.7", "for-each": "^0.3.3", "gopd": "^1.0.1", "has-proto": "^1.0.3", - "is-typed-array": "^1.1.13" + "is-typed-array": "^1.1.13", + "reflect.getprototypeof": "^1.0.6" }, "engines": { "node": ">= 0.4" @@ -15002,16 +15006,16 @@ } }, "node_modules/typed-array-length": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/typed-array-length/-/typed-array-length-1.0.6.tgz", - "integrity": "sha512-/OxDN6OtAk5KBpGb28T+HZc2M+ADtvRxXrKKbUwtsLgdoxgX13hyy7ek6bFRl5+aBs2yZzB0c4CnQfAtVypW/g==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/typed-array-length/-/typed-array-length-1.0.7.tgz", + "integrity": "sha512-3KS2b+kL7fsuk/eJZ7EQdnEmQoaho/r6KUef7hxvltNA5DR8NAUM+8wJMbJyZ4G9/7i3v5zPBIMN5aybAh2/Jg==", "dependencies": { "call-bind": "^1.0.7", "for-each": "^0.3.3", "gopd": "^1.0.1", - "has-proto": "^1.0.3", "is-typed-array": "^1.1.13", - "possible-typed-array-names": "^1.0.0" + "possible-typed-array-names": "^1.0.0", + "reflect.getprototypeof": "^1.0.6" }, "engines": { "node": ">= 0.4" @@ -15627,15 +15631,16 @@ } }, "node_modules/which-builtin-type": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/which-builtin-type/-/which-builtin-type-1.1.4.tgz", - "integrity": "sha512-bppkmBSsHFmIMSl8BO9TbsyzsvGjVoppt8xUiGzwiu/bhDCGxnpOKCxgqj6GuyHE0mINMDecBFPlOm2hzY084w==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/which-builtin-type/-/which-builtin-type-1.2.0.tgz", + "integrity": "sha512-I+qLGQ/vucCby4tf5HsLmGueEla4ZhwTBSqaooS+Y0BuxN4Cp+okmGuV+8mXZ84KDI9BA+oklo+RzKg0ONdSUA==", "dependencies": { + "call-bind": "^1.0.7", "function.prototype.name": "^1.1.6", "has-tostringtag": "^1.0.2", "is-async-function": "^2.0.0", "is-date-object": "^1.0.5", - "is-finalizationregistry": "^1.0.2", + "is-finalizationregistry": "^1.1.0", "is-generator-function": "^1.0.10", "is-regex": "^1.1.4", "is-weakref": "^1.0.2", diff --git a/example-dimo-auth/package.json b/example-dimo-auth/package.json index 68a8946..d5f9e57 100644 --- a/example-dimo-auth/package.json +++ b/example-dimo-auth/package.json @@ -10,7 +10,7 @@ "@types/node": "^16.18.114", "@types/react": "^18.3.11", "@types/react-dom": "^18.3.1", - "@dimo-network/login-with-dimo": "file:./dimo-network-login-with-dimo-0.0.8.tgz", + "@dimo-network/login-with-dimo": "file:./dimo-network-login-with-dimo-0.0.9.tgz", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", diff --git a/example-dimo-auth/src/App.tsx b/example-dimo-auth/src/App.tsx index 8504263..c09f1fc 100644 --- a/example-dimo-auth/src/App.tsx +++ b/example-dimo-auth/src/App.tsx @@ -4,6 +4,7 @@ import "./App.css"; import { LoginWithDimo, ShareVehiclesWithDimo, + ExecuteAdvancedTransactionWithDimo, initializeDimoSDK, useDimoAuthState, } from "@dimo-network/login-with-dimo"; @@ -12,6 +13,1082 @@ function App() { const [permissionsEnabled, setPermissionsEnabled] = useState(false); const { isAuthenticated, getValidJWT } = useDimoAuthState(); + const sampleAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "previousAdmin", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "newAdmin", + type: "address", + }, + ], + name: "AdminChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "owner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "spender", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Approval", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "beacon", + type: "address", + }, + ], + name: "BeaconUpgraded", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "delegator", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "fromDelegate", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "toDelegate", + type: "address", + }, + ], + name: "DelegateChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "delegate", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "previousBalance", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "newBalance", + type: "uint256", + }, + ], + name: "DelegateVotesChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint8", + name: "version", + type: "uint8", + }, + ], + name: "Initialized", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "Paused", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + indexed: true, + internalType: "bytes32", + name: "previousAdminRole", + type: "bytes32", + }, + { + indexed: true, + internalType: "bytes32", + name: "newAdminRole", + type: "bytes32", + }, + ], + name: "RoleAdminChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleGranted", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleRevoked", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Transfer", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "Unpaused", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "implementation", + type: "address", + }, + ], + name: "Upgraded", + type: "event", + }, + { + inputs: [], + name: "DEFAULT_ADMIN_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "DEPOSITOR_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "DOMAIN_SEPARATOR", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "MINTER_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "PAUSER_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "UPGRADER_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "address", + name: "spender", + type: "address", + }, + ], + name: "allowance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "approve", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "balanceOf", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "burn", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "burnFrom", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + { + internalType: "uint32", + name: "pos", + type: "uint32", + }, + ], + name: "checkpoints", + outputs: [ + { + components: [ + { + internalType: "uint32", + name: "fromBlock", + type: "uint32", + }, + { + internalType: "uint224", + name: "votes", + type: "uint224", + }, + ], + internalType: "struct ERC20VotesUpgradeable.Checkpoint", + name: "", + type: "tuple", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "decimals", + outputs: [ + { + internalType: "uint8", + name: "", + type: "uint8", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "subtractedValue", + type: "uint256", + }, + ], + name: "decreaseAllowance", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "delegatee", + type: "address", + }, + ], + name: "delegate", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "delegatee", + type: "address", + }, + { + internalType: "uint256", + name: "nonce", + type: "uint256", + }, + { + internalType: "uint256", + name: "expiry", + type: "uint256", + }, + { + internalType: "uint8", + name: "v", + type: "uint8", + }, + { + internalType: "bytes32", + name: "r", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "s", + type: "bytes32", + }, + ], + name: "delegateBySig", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "delegates", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "bytes", + name: "depositData", + type: "bytes", + }, + ], + name: "deposit", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "blockNumber", + type: "uint256", + }, + ], + name: "getPastTotalSupply", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + { + internalType: "uint256", + name: "blockNumber", + type: "uint256", + }, + ], + name: "getPastVotes", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + ], + name: "getRoleAdmin", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "getVotes", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "grantRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "hasRole", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "addedValue", + type: "uint256", + }, + ], + name: "increaseAllowance", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "mint", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "name", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + ], + name: "nonces", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "numCheckpoints", + outputs: [ + { + internalType: "uint32", + name: "", + type: "uint32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "pause", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "paused", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "value", + type: "uint256", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + { + internalType: "uint8", + name: "v", + type: "uint8", + }, + { + internalType: "bytes32", + name: "r", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "s", + type: "bytes32", + }, + ], + name: "permit", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "proxiableUUID", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "renounceRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "revokeRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes4", + name: "interfaceId", + type: "bytes4", + }, + ], + name: "supportsInterface", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "pure", + type: "function", + }, + { + inputs: [], + name: "symbol", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "totalSupply", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "transfer", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "from", + type: "address", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "transferFrom", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "unpause", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newImplementation", + type: "address", + }, + ], + name: "upgradeTo", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newImplementation", + type: "address", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "upgradeToAndCall", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "withdraw", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + ]; + // Toggle handler const handleToggle = () => { setPermissionsEnabled(!permissionsEnabled); @@ -47,12 +1124,27 @@ function App() {

Popup Example

{isAuthenticated ? ( - console.log("Success:", authData)} - onError={(error: any) => console.error("Error:", error)} - permissionTemplateId={"1"} - /> + <> + console.log("Success:", authData)} + onError={(error: any) => console.error("Error:", error)} + permissionTemplateId={"1"} + /> + + + console.log("Success:", transactionHash) + } + onError={(error: any) => console.error("Error:", error)} + address="0x21cFE003997fB7c2B3cfe5cf71e7833B7B2eCe10" + value="0" + abi={sampleAbi} + functionName="transfer" + args={["0x62b98e019e0d3e4A1Ad8C786202e09017Bd995e1", "0"]} + /> + ) : ( console.error("Error:", error)} permissionTemplateId={"1"} /> + + console.log("Success:", authData)} + onError={(error: any) => console.error("Error:", error)} + address="0x21cFE003997fB7c2B3cfe5cf71e7833B7B2eCe10" + value="0" + abi={sampleAbi} + functionName="transfer" + args={["0x62b98e019e0d3e4A1Ad8C786202e09017Bd995e1", "0"]} + /> diff --git a/sdk/package.json b/sdk/package.json index 7846f94..bc1dbff 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@dimo-network/login-with-dimo", - "version": "0.0.8", + "version": "0.0.9", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/sdk/src/auth/embedAuth.ts b/sdk/src/auth/embedAuth.ts index 64163b3..be49361 100644 --- a/sdk/src/auth/embedAuth.ts +++ b/sdk/src/auth/embedAuth.ts @@ -1,9 +1,14 @@ import { EntryState } from "../enums/globalEnums"; +import { TransactionData } from "../types/TransactionData"; import { handleMessageForEmbed } from "../utils/eventHandler"; export const embedAuth = ( entryState: EntryState, - onSuccess: (authData: { token: string }) => void, + onSuccess: (data: { + token: string; + transactionHash?: string; + transactionReceipt?: any; + }) => void, onError: (error: Error) => void, setAuthenticated: React.Dispatch>, dimoLogin: string, @@ -12,7 +17,8 @@ export const embedAuth = ( apiKey?: string, permissionTemplateId?: string, vehicles?: string[], - vehicleMakes?: string[] + vehicleMakes?: string[], + transactionData?: TransactionData ) => { const cleanup = handleMessageForEmbed( dimoLogin, @@ -25,6 +31,7 @@ export const embedAuth = ( apiKey, permissionTemplateId, vehicles, - vehicleMakes + vehicleMakes, + transactionData ); }; diff --git a/sdk/src/auth/popupAuth.ts b/sdk/src/auth/popupAuth.ts index 5dc397a..b79263e 100644 --- a/sdk/src/auth/popupAuth.ts +++ b/sdk/src/auth/popupAuth.ts @@ -1,9 +1,14 @@ import { EntryState } from "../enums/globalEnums"; +import { TransactionData } from "../types/TransactionData"; import { handleMessageForPopup } from "../utils/eventHandler"; export const popupAuth = ( entryState: EntryState, - onSuccess: (authData: { token: string }) => void, + onSuccess: (data: { + token: string; + transactionHash?: string; + transactionReceipt?: any; + }) => void, onError: (error: Error) => void, setAuthenticated: React.Dispatch>, dimoLogin: string, @@ -12,7 +17,8 @@ export const popupAuth = ( apiKey?: string, permissionTemplateId?: string, vehicles?: string[], - vehicleMakes?: string[] + vehicleMakes?: string[], + transactionData?: TransactionData ) => { try { const popup = window.open( @@ -38,7 +44,8 @@ export const popupAuth = ( apiKey, permissionTemplateId, vehicles, - vehicleMakes + vehicleMakes, + transactionData ); } catch (error: unknown) { if (error instanceof Error) { diff --git a/sdk/src/auth/redirectAuth.ts b/sdk/src/auth/redirectAuth.ts index f66974a..79e7505 100644 --- a/sdk/src/auth/redirectAuth.ts +++ b/sdk/src/auth/redirectAuth.ts @@ -1,4 +1,5 @@ import { EntryState } from "../enums/globalEnums"; +import { TransactionData } from "../types/TransactionData"; export const redirectAuth = ( entryState: EntryState, @@ -11,22 +12,40 @@ export const redirectAuth = ( permissionTemplateId?: string, vehicles?: string[], vehicleMakes?: string[], + transactionData?: TransactionData // Add transactionData as a parameter ) => { - // Create URLSearchParams instance const params = new URLSearchParams(); if (clientId) params.append("clientId", clientId); if (redirectUri) params.append("redirectUri", redirectUri); - if (permissionTemplateId) params.append("permissionTemplateId", permissionTemplateId); + if (permissionTemplateId) + params.append("permissionTemplateId", permissionTemplateId); if (entryState) params.append("entryState", entryState); if (vehicles && vehicles.length > 0) { - vehicles.forEach(vehicle => params.append("vehicles", vehicle)); - } + vehicles.forEach((vehicle) => params.append("vehicles", vehicle)); + } if (vehicleMakes && vehicleMakes.length > 0) { - vehicleMakes.forEach(vehicleMake => params.append("vehicleMakes", vehicleMake)); - } + vehicleMakes.forEach((vehicleMake) => + params.append("vehicleMakes", vehicleMake) + ); + } + + // Serialize and encode transactionData + if (transactionData) { + const serializedTransactionData = encodeURIComponent( + JSON.stringify(transactionData) + ); + + if (serializedTransactionData.length > 1000) { + console.warn( + "Serialized transactionData is too large for a URL parameter." + ); + } else { + params.append("transactionData", serializedTransactionData); + } + } // Construct the full URL window.location.href = `${dimoLogin}?${params.toString()}`; diff --git a/sdk/src/components/BaseDimoButton.tsx b/sdk/src/components/BaseDimoButton.tsx index 5b5ad7f..f3ec73a 100644 --- a/sdk/src/components/BaseDimoButton.tsx +++ b/sdk/src/components/BaseDimoButton.tsx @@ -5,18 +5,28 @@ import { redirectAuth } from "../auth/redirectAuth"; import { getDimoConfig } from "../config/sdkConfig"; import { EntryState } from "../enums/globalEnums"; import "../styles/BaseDimoButton.css"; -import { DimoAuthProvider, useDimoAuthState, useDimoAuthUpdater } from "../auth/context/DimoAuthContext"; +import { + DimoAuthProvider, + useDimoAuthState, + useDimoAuthUpdater, +} from "../auth/context/DimoAuthContext"; +import { TransactionData } from "../types/TransactionData"; interface BaseDimoButtonProps { mode: "popup" | "embed" | "redirect"; entryState: EntryState; - onSuccess: (authData: { token: string }) => void; // Success callback + onSuccess: (data: { + token: string; + transactionHash?: string; + transactionReceipt?: any; + }) => void; // Success callback onError: (error: Error) => void; // Error callback buttonLabel: (authenticated: boolean) => string; // Function to determine button label dynamically disableIfAuthenticated?: boolean; // Disable button if authenticated (default: false) permissionTemplateId?: string; vehicles?: string[]; vehicleMakes?: string[]; + transactionData?: TransactionData; } const BaseDimoButton: React.FC = ({ @@ -29,14 +39,14 @@ const BaseDimoButton: React.FC = ({ permissionTemplateId, vehicles, vehicleMakes, + transactionData, }) => { const { clientId, redirectUri, apiKey, environment } = getDimoConfig(); //DimoAuthProvider contexts, the following can only be used when the component using them is wrapped in a - const { isAuthenticated } = useDimoAuthState(); + const { isAuthenticated } = useDimoAuthState(); const { setAuthenticated } = useDimoAuthUpdater(); - const dimoLogin = environment === "development" ? "https://login.dev.dimo.org" @@ -56,7 +66,8 @@ const BaseDimoButton: React.FC = ({ apiKey, permissionTemplateId, vehicles, - vehicleMakes + vehicleMakes, + transactionData ); break; case "redirect": @@ -70,7 +81,8 @@ const BaseDimoButton: React.FC = ({ apiKey, permissionTemplateId, vehicles, - vehicleMakes + vehicleMakes, + transactionData ); break; default: @@ -92,7 +104,8 @@ const BaseDimoButton: React.FC = ({ apiKey, permissionTemplateId, vehicles, - vehicleMakes + vehicleMakes, + transactionData ); } }; diff --git a/sdk/src/components/ExecuteAdvancedTransactionWithDimo.tsx b/sdk/src/components/ExecuteAdvancedTransactionWithDimo.tsx new file mode 100644 index 0000000..f6c9f9c --- /dev/null +++ b/sdk/src/components/ExecuteAdvancedTransactionWithDimo.tsx @@ -0,0 +1,47 @@ +import React from "react"; +import BaseDimoButton from "./BaseDimoButton"; +import { EntryState } from "../enums/globalEnums"; +import { TransactionData } from "../types/TransactionData"; + +interface ExecuteAdvancedTransactionProps { + mode: "popup" | "embed" | "redirect"; + onSuccess: (data: { + token: string; + transactionHash?: string; + transactionReceipt?: any; + }) => void; // Success callback + onError: (error: Error) => void; // Error callback + address: string; + value: string; + abi: any; + functionName: string; + args: string[]; +} + +const ExecuteAdvancedTransactionWithDimo: React.FC< + ExecuteAdvancedTransactionProps +> = ({ mode, onSuccess, onError, address, value, abi, functionName, args }) => { + if (!address || !value || !abi || !functionName || !args) { + throw new Error("Missing required transaction parameters."); + } + const transactionData: TransactionData = { + address, + value, // BigInt to string + abi, + functionName, + args, + }; + + return ( + "Execute Advanced Transaction with Dimo"} + transactionData={transactionData} + /> + ); +}; + +export default ExecuteAdvancedTransactionWithDimo; diff --git a/sdk/src/enums/globalEnums.ts b/sdk/src/enums/globalEnums.ts index 2fe9503..86cb6de 100644 --- a/sdk/src/enums/globalEnums.ts +++ b/sdk/src/enums/globalEnums.ts @@ -3,7 +3,7 @@ export enum EntryState { OTP_INPUT = "OTP_INPUT", SUCCESS = "SUCCESS", VEHICLE_MANAGER = "VEHICLE_MANAGER", - EXECUTE_TRANSACTION = "EXECUTE_TRANSACTION", + ADVANCED_TRANSACTION = "ADVANCED_TRANSACTION", ERROR = "ERROR", LOADING = "LOADING", } diff --git a/sdk/src/index.ts b/sdk/src/index.ts index a012481..ebe2814 100644 --- a/sdk/src/index.ts +++ b/sdk/src/index.ts @@ -1,6 +1,7 @@ // Export components export { default as LoginWithDimo } from './components/LoginWithDimo'; export { default as ShareVehiclesWithDimo } from './components/ShareVehiclesWithDimo'; +export { default as ExecuteAdvancedTransactionWithDimo } from './components/ExecuteAdvancedTransactionWithDimo'; // Export config initialization export { initializeDimoSDK, getDimoConfig } from './config/sdkConfig'; diff --git a/sdk/src/types/TransactionData.ts b/sdk/src/types/TransactionData.ts new file mode 100644 index 0000000..e916390 --- /dev/null +++ b/sdk/src/types/TransactionData.ts @@ -0,0 +1,7 @@ +export interface TransactionData { + address: string; + value: string; + abi: any; // Serialized ABI + functionName: string; + args: string[]; +} diff --git a/sdk/src/utils/eventHandler.ts b/sdk/src/utils/eventHandler.ts index 3a1d271..01e1a6b 100644 --- a/sdk/src/utils/eventHandler.ts +++ b/sdk/src/utils/eventHandler.ts @@ -1,5 +1,6 @@ import { EntryState } from "../enums/globalEnums"; import { storeJWTInCookies } from "../storage/storageManager"; +import { TransactionData } from "../types/TransactionData"; /** * @file eventHandler.ts @@ -21,7 +22,11 @@ function getDomain(url: string) { export const handleMessageForPopup = ( expectedOrigin: string, entryState: EntryState, - onSuccess: (authData: { token: string }) => void, + onSuccess: (data: { + token: string; + transactionHash?: string; + transactionReceipt?: any; + }) => void, onError: (error: Error) => void, setAuthenticated: React.Dispatch>, popup?: Window | null, @@ -31,6 +36,7 @@ export const handleMessageForPopup = ( permissionTemplateId?: string, vehicles?: string[], vehicleMakes?: string[], + transactionData?: TransactionData ) => { const popupListener = (event: MessageEvent) => { if (getDomain(event.origin) !== getDomain(expectedOrigin)) { @@ -38,13 +44,12 @@ export const handleMessageForPopup = ( return; } - const { eventType, token, authType } = event.data; + const { eventType, token, authType, transactionHash, message } = event.data; // Handle the "READY" message if (eventType === "READY") { // Once the "READY" message is received, send the credentials if (popup) { - //Temporary Fix //Seems like on Safari, and Mobile Browsers - the popup is not ready to receive messages, even after sending a "READY" message //The set timeout acts as a solution, by modifying the callback loop @@ -57,6 +62,7 @@ export const handleMessageForPopup = ( permissionTemplateId, vehicles, vehicleMakes, + transactionData, entryState, eventType: "AUTH_INIT", }, @@ -82,6 +88,16 @@ export const handleMessageForPopup = ( window.removeEventListener("message", popupListener); } + + if (eventType === "transactionResponse") { + if (transactionHash) { + onSuccess({ token: "", transactionHash }); + } + } + + if (eventType === "DIMO_ERROR") { + onError(message); + } }; // Add event listener specifically for popup auth @@ -94,7 +110,11 @@ export const handleMessageForPopup = ( export const handleMessageForEmbed = ( expectedOrigin: string, entryState: EntryState, - onSuccess: (authData: { token: string }) => void, + onSuccess: (data: { + token: string; + transactionHash?: string; + transactionReceipt?: any; + }) => void, onError: (error: Error) => void, setAuthenticated: React.Dispatch>, clientId?: string, @@ -103,6 +123,7 @@ export const handleMessageForEmbed = ( permissionTemplateId?: string, vehicles?: string[], vehicleMakes?: string[], + transactionData?: TransactionData ) => { const embedListener = (event: MessageEvent) => { if (getDomain(event.origin) !== getDomain(expectedOrigin)) { @@ -110,7 +131,8 @@ export const handleMessageForEmbed = ( return; } - const { eventType, token, authType } = event.data; + const { eventType, token, authType, transactionHash, transactionReceipt } = + event.data; if (eventType === "READY") { // Once the "READY" message is received, send the credentials @@ -126,6 +148,7 @@ export const handleMessageForEmbed = ( vehicles, vehicleMakes, entryState, + transactionData, eventType: "AUTH_INIT", }; @@ -140,6 +163,14 @@ export const handleMessageForEmbed = ( setAuthenticated(true); onSuccess({ token }); } + + if (eventType === "transactionResponse") { + if (transactionHash || transactionReceipt) { + onSuccess({ token: "", transactionHash, transactionReceipt }); + } else { + onError(Error("Could not execute transaction")); + } + } }; // Add event listener specifically for embed auth