{
  "type": "script",
  "title": "Wallet derivation script",
  "description": "Derives six spending and six staking keys of the current wallet and builds every kind of address they allow: a reward address, hierarchical deterministic, delegation portfolio and anonymous addresses, native script multisig treasuries and Plutus smart contract addresses. Nothing is submitted on-chain and every address is exported back to dapp for inspection",
  "require": {
    "not": {
      "walletTypeIn": [
        "extension"
      ]
    }
  },
  "run": {
    "HDSpendKeys": {
      "type": "deriveKeys",
      "keys": [
        {
          "name": "spend00",
          "kind": "spend",
          "accountIndex": 0,
          "addressIndex": 0
        },
        {
          "name": "spend01",
          "kind": "spend",
          "accountIndex": 0,
          "addressIndex": 1
        },
        {
          "name": "spend02",
          "kind": "spend",
          "accountIndex": 0,
          "addressIndex": 2
        },
        {
          "name": "spend03",
          "kind": "spend",
          "accountIndex": 0,
          "addressIndex": 3
        },
        {
          "name": "spend04",
          "kind": "spend",
          "accountIndex": 0,
          "addressIndex": 4
        },
        {
          "name": "spend05",
          "kind": "spend",
          "accountIndex": 0,
          "addressIndex": 5
        }
      ]
    },
    "HDStakeKeys": {
      "type": "deriveKeys",
      "keys": [
        {
          "name": "stake00",
          "kind": "stake",
          "accountIndex": 0,
          "addressIndex": 0
        },
        {
          "name": "stake01",
          "kind": "stake",
          "accountIndex": 0,
          "addressIndex": 1
        },
        {
          "name": "stake02",
          "kind": "stake",
          "accountIndex": 0,
          "addressIndex": 2
        },
        {
          "name": "stake03",
          "kind": "stake",
          "accountIndex": 0,
          "addressIndex": 3
        },
        {
          "name": "stake04",
          "kind": "stake",
          "accountIndex": 0,
          "addressIndex": 4
        },
        {
          "name": "stake05",
          "kind": "stake",
          "accountIndex": 0,
          "addressIndex": 5
        }
      ]
    },
    "hierarchicalDeterministic": {
      "type": "script",
      "run": [
        {
          "type": "script",
          "exportAs": "RewardAddress",
          "run": [
            {
              "type": "buildAddress",
              "name": "RewardAddress",
              "addr": {
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.0.pubKeyHashHex')}"
              }
            }
          ]
        },
        {
          "type": "script",
          "exportAs": "HierarchicalDeterministicWallet",
          "run": [
            {
              "type": "buildAddress",
              "name": "HierarchicalDeterministicWallet#0",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.0.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.0.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "HierarchicalDeterministicWallet#1",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.1.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.0.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "HierarchicalDeterministicWallet#2",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.2.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.0.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "HierarchicalDeterministicWallet#3",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.3.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.0.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "HierarchicalDeterministicWallet#3",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.4.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.0.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "HierarchicalDeterministicWallet#5",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.5.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.0.pubKeyHashHex')}"
              }
            }
          ]
        },
        {
          "type": "script",
          "exportAs": "DelegationPortfolioWallet",
          "run": [
            {
              "type": "buildAddress",
              "name": "DelegationPortfolioWallet#0",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.0.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.0.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "DelegationPortfolioWallet#1",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.0.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.1.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "DelegationPortfolioWallet#2",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.0.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.2.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "DelegationPortfolioWallet#3",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.0.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.3.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "DelegationPortfolioWallet#4",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.0.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.4.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "DelegationPortfolioWallet#5",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.0.pubKeyHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.5.pubKeyHashHex')}"
              }
            }
          ]
        },
        {
          "type": "script",
          "exportAs": "AnonymousHierarchicalDeterministicWallet",
          "run": [
            {
              "type": "buildAddress",
              "name": "AnonymousHierarchicalDeterministicWallet#0",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.0.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "AnonymousHierarchicalDeterministicWallet#1",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.1.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "AnonymousHierarchicalDeterministicWallet#2",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.2.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "AnonymousHierarchicalDeterministicWallet#3",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.3.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "AnonymousHierarchicalDeterministicWallet#4",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.4.pubKeyHashHex')}"
              }
            },
            {
              "type": "buildAddress",
              "name": "AnonymousHierarchicalDeterministicWallet#5",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.5.pubKeyHashHex')}"
              }
            }
          ]
        }
      ]
    },
    "multisig": {
      "type": "script",
      "run": {
        "spendingScript": {
          "type": "nativeScript",
          "name": "spendingScript",
          "script": {
            "scriptHex": "820181820400"
          }
        },
        "stakingScript": {
          "type": "nativeScript",
          "name": "stakingScript",
          "script": {
            "scriptHex": "82018382041a0005d90d8200581c111fc9cc6fd34bd2783001b3fbf7b456beb93a38d24a1e06542dc6fb82051a0008e909"
          }
        },
        "treasuries": {
          "type": "script",
          "exportAs": "MultisigWallets",
          "run": {
            "SpendingTreasuryWallet": {
              "type": "buildAddress",
              "name": "SpendingTreasuryWallet",
              "addr": {
                "spendScriptHashHex": "{get('cache.multisig.spendingScript.scriptHashHex')}"
              }
            },
            "StakingTreasuryWallet": {
              "type": "buildAddress",
              "name": "StakingTreasuryWallet",
              "addr": {
                "stakeScriptHashHex": "{get('cache.multisig.stakingScript.scriptHashHex')}"
              }
            },
            "SpendingAndStakingTreasuryWallet": {
              "type": "buildAddress",
              "name": "SpendingAndStakingTreasuryWallet",
              "addr": {
                "spendScriptHashHex": "{get('cache.multisig.spendingScript.scriptHashHex')}",
                "stakeScriptHashHex": "{get('cache.multisig.stakingScript.scriptHashHex')}"
              }
            }
          }
        }
      }
    },
    "smartContracts": {
      "type": "script",
      "run": {
        "sc01": {
          "type": "plutusScript",
          "name": "plutusScript",
          "script": {
            "lang": "plutus_v2",
            "scriptHex": "4e4d01000033222220051200120011"
          }
        },
        "smartContractWallet": {
          "type": "script",
          "exportAs": "SmartContractWallets",
          "run": {
            "SmartContractWallet": {
              "type": "buildAddress",
              "name": "SmartContractWallet",
              "addr": {
                "spendScriptHashHex": "{get('cache.smartContracts.sc01.scriptHashHex')}"
              }
            },
            "SmartContractUserStakingWallet": {
              "type": "buildAddress",
              "name": "SmartContractUserStakingWallet",
              "addr": {
                "spendScriptHashHex": "{get('cache.smartContracts.sc01.scriptHashHex')}",
                "stakePubKeyHashHex": "{get('cache.HDStakeKeys.0.pubKeyHashHex')}"
              }
            },
            "SmartContractUserSpendingWallet": {
              "type": "buildAddress",
              "name": "SmartContractUserSpendingWallet",
              "addr": {
                "spendPubKeyHashHex": "{get('cache.HDSpendKeys.0.pubKeyHashHex')}",
                "stakeScriptHashHex": "{get('cache.smartContracts.sc01.scriptHashHex')}"
              }
            },
            "SmartContractMultiSigStakingWallet": {
              "type": "buildAddress",
              "name": "SmartContractMultiSigStakingWallet",
              "addr": {
                "spendScriptHashHex": "{get('cache.smartContracts.sc01.scriptHashHex')}",
                "stakeScriptHashHex": "{get('cache.multisig.stakingScript.scriptHashHex')}"
              }
            }
          }
        }
      }
    }
  }
}