Skip to content

Commit

Permalink
[Internet Computer] Add Internet Computer (ICP) Chain (#3470)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfinity-ryancroote authored Oct 23, 2023
1 parent b08c6f3 commit 92fc9bd
Show file tree
Hide file tree
Showing 57 changed files with 4,534 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,6 @@ class CoinAddressDerivationTests {
NOBLE -> assertEquals("noble142j9u5eaduzd7faumygud6ruhdwme98qc8l3wa", address)
ROOTSTOCK -> assertEquals("0xA2D7065F94F838a3aB9C04D67B312056846424Df", address)
SEI -> assertEquals("sei142j9u5eaduzd7faumygud6ruhdwme98qagm0sj", address)
INTERNETCOMPUTER -> assertEquals("b9a13d974ee9db036d5abc5b66ace23e513cb5676f3996626c7717c339a3ee87", address)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright © 2017-2023 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.

package com.trustwallet.core.app.blockchains.internetcomputer

import com.trustwallet.core.app.utils.toHex
import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.*

class TestInternetComputerAddress {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun testAddress() {
val key = PrivateKey("ee42eaada903e20ef6e5069f0428d552475c1ea7ed940842da6448f6ef9d48e7".toHexByteArray())
val pubkey = key.getPublicKeySecp256k1(false);
val address = AnyAddress(pubkey, CoinType.INTERNETCOMPUTER)
val expected = AnyAddress("2f25874478d06cf68b9833524a6390d0ba69c566b02f46626979a3d6a4153211", CoinType.INTERNETCOMPUTER)

assertEquals(pubkey.data().toHex(), "0x048542e6fb4b17d6dfcac3948fe412c00d626728815ee7cc70509603f1bc92128a6e7548f3432d6248bc49ff44a1e50f6389238468d17f7d7024de5be9b181dbc8")
assertEquals(address.description(), expected.description())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright © 2017-2023 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.

package com.trustwallet.core.app.blockchains.internetcomputer

import com.google.protobuf.ByteString
import com.trustwallet.core.app.utils.Numeric
import com.trustwallet.core.app.utils.toHex
import com.trustwallet.core.app.utils.toHexByteArray
import com.trustwallet.core.app.utils.toHexBytes
import com.trustwallet.core.app.utils.toHexBytesInByteString
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.java.AnySigner
import wallet.core.jni.*
import wallet.core.jni.proto.InternetComputer
import wallet.core.jni.proto.InternetComputer.SigningOutput

class TestInternetComputerSigner {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun InternetComputerTransactionSigning() {
val key = PrivateKey("227102911bb99ce7285a55f952800912b7d22ebeeeee59d77fc33a5d7c7080be".toHexByteArray())

val input = InternetComputer.SigningInput.newBuilder()
.setTransaction(InternetComputer.Transaction.newBuilder().apply {
transfer = InternetComputer.Transaction.Transfer.newBuilder().apply {
toAccountIdentifier = "943d12e762f43806782f524b8f90297298a6d79e4749b41b585ec427409c826a"
amount = 100000000
memo = 0
currentTimestampNanos = 1691709940000000000
}.build()
}.build())
.setPrivateKey(ByteString.copyFrom(key.data()))
val output = AnySigner.sign(input.build(), CoinType.INTERNETCOMPUTER, SigningOutput.parser())
assertEquals(output.signedTransaction.toByteArray().toHex(), "0x81826b5452414e53414354494f4e81a266757064617465a367636f6e74656e74a66c726571756573745f747970656463616c6c6e696e67726573735f6578706972791b177a297215cfe8006673656e646572581d971cd2ddeecd1cf1b28be914d7a5c43441f6296f1f9966a7c8aff68d026b63616e69737465725f69644a000000000000000201016b6d6574686f645f6e616d656773656e645f706263617267583b0a0012070a050880c2d72f2a220a20943d12e762f43806782f524b8f90297298a6d79e4749b41b585ec427409c826a3a0a088090caa5a3a78abd176d73656e6465725f7075626b65799858183018561830100607182a1886184818ce183d02010605182b188104000a0318420004183d18ab183a182118a81838184d184c187e1852188a187e18dc18d8184418ea18cd18c5189518ac188518b518bc181d188515186318bc18e618ab18d2184318d3187c184f18cd18f018de189b18b5181918dd18ef1889187218e71518c40418d4189718881843187218c611182e18cc18e6186b182118630218356a73656e6465725f736967984013186f18b9181c189818b318a8186518b2186118d418971618b1187d18eb185818e01826182f1873183b185018cb185d18ef18d81839186418b3183218da1824182f184e18a01880182718c0189018c918a018fd18c418d9189e189818b318ef1874183b185118e118a51864185918e718ed18c71889186c1822182318ca6a726561645f7374617465a367636f6e74656e74a46c726571756573745f747970656a726561645f73746174656e696e67726573735f6578706972791b177a297215cfe8006673656e646572581d971cd2ddeecd1cf1b28be914d7a5c43441f6296f1f9966a7c8aff68d0265706174687381824e726571756573745f7374617475735820e8fbc2d5b0bf837b3a369249143e50d4476faafb2dd620e4e982586a51ebcf1e6d73656e6465725f7075626b65799858183018561830100607182a1886184818ce183d02010605182b188104000a0318420004183d18ab183a182118a81838184d184c187e1852188a187e18dc18d8184418ea18cd18c5189518ac188518b518bc181d188515186318bc18e618ab18d2184318d3187c184f18cd18f018de189b18b5181918dd18ef1889187218e71518c40418d4189718881843187218c611182e18cc18e6186b182118630218356a73656e6465725f7369679840182d182718201888188618ce187f0c182a187a18d718e818df18fb18d318d41118a5186a184b18341842185318d718e618e8187a1828186c186a183618461418f3183318bd18a618a718bc18d918c818b7189d186e1865188418ff18fd18e418e9187f181b18d705184818b21872187818d6181c161833184318a2")
}

@Test
fun InternetComputerTransactionSigningWithInvalidToAccountIdentifier() {
val key = PrivateKey("227102911bb99ce7285a55f952800912b7d22ebeeeee59d77fc33a5d7c7080be".toHexByteArray())

val input = InternetComputer.SigningInput.newBuilder()
.setTransaction(InternetComputer.Transaction.newBuilder().apply {
transfer = InternetComputer.Transaction.Transfer.newBuilder().apply {
toAccountIdentifier = "643d12e762f43806782f524b8f90297298a6d79e4749b41b585ec427409c826b"
amount = 100000000
memo = 0
currentTimestampNanos = 1691709940000000000
}.build()
}.build())
.setPrivateKey(ByteString.copyFrom(key.data()))
val output = AnySigner.sign(input.build(), CoinType.INTERNETCOMPUTER, SigningOutput.parser())
assertEquals(output.error.number, 16)
}

@Test
fun InternetComputerTransactionSigningWithInvalidAmount() {
val key = PrivateKey("227102911bb99ce7285a55f952800912b7d22ebeeeee59d77fc33a5d7c7080be".toHexByteArray())

val input = InternetComputer.SigningInput.newBuilder()
.setTransaction(InternetComputer.Transaction.newBuilder().apply {
transfer = InternetComputer.Transaction.Transfer.newBuilder().apply {
toAccountIdentifier = "943d12e762f43806782f524b8f90297298a6d79e4749b41b585ec427409c826a"
amount = 0
memo = 0
currentTimestampNanos = 1691709940000000000
}.build()
}.build())
.setPrivateKey(ByteString.copyFrom(key.data()))
val output = AnySigner.sign(input.build(), CoinType.INTERNETCOMPUTER, SigningOutput.parser())
assertEquals(output.error.number, 23)
}
}
1 change: 1 addition & 0 deletions docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This list is generated from [./registry.json](../registry.json)
| 194 | EOS | EOS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/eos/info/logo.png" width="32" /> | <http://eos.io> |
| 195 | Tron | TRX | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png" width="32" /> | <https://tron.network> |
| 204 | OpBNB | BNB | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/opbnb/info/logo.png" width="32" /> | <https://opbnb.bnbchain.org/en> |
| 223 | Internet Computer | ICP | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/internet_computer/info/logo.png" width="32" /> | <https://internetcomputer.org> |
| 235 | FIO | FIO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/fio/info/logo.png" width="32" /> | <https://fioprotocol.io> |
| 242 | Nimiq | NIM | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/nimiq/info/logo.png" width="32" /> | <https://nimiq.com> |
| 283 | Algorand | ALGO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/algorand/info/logo.png" width="32" /> | <https://www.algorand.com/> |
Expand Down
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWBlockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum TWBlockchain {
TWBlockchainTheOpenNetwork = 49,
TWBlockchainSui = 50,
TWBlockchainGreenfield = 51,
TWBlockchainInternetComputer = 52,
};

TW_EXTERN_C_END
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWCoinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ enum TWCoinType {
TWCoinTypeGreenfield = 5600,
TWCoinTypeMantle = 5000,
TWCoinTypeZenEON = 7332,
TWCoinTypeInternetComputer = 223,
};

/// Returns the blockchain for a coin type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,6 @@ class CoinAddressDerivationTests {
Noble -> "noble142j9u5eaduzd7faumygud6ruhdwme98qc8l3wa"
Rootstock -> "0xA2D7065F94F838a3aB9C04D67B312056846424Df"
Sei -> "sei142j9u5eaduzd7faumygud6ruhdwme98qagm0sj"
InternetComputer -> "b9a13d974ee9db036d5abc5b66ace23e513cb5676f3996626c7717c339a3ee87"
}
}
31 changes: 30 additions & 1 deletion registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,6 @@
"documentation": "https://developer.algorand.org/docs/algod-rest-paths"
}
},

{
"id": "iotex",
"name": "IoTeX",
Expand Down Expand Up @@ -4446,5 +4445,35 @@
"rpc": "https://neon-proxy-mainnet.solana.p2p.org/",
"documentation": "https://docs.neonfoundation.io/docs/quick_start"
}
},
{
"id": "internet_computer",
"name": "Internet Computer",
"coinId": 223,
"symbol": "ICP",
"decimals": 8,
"blockchain": "InternetComputer",
"derivation": [
{
"path": "m/44'/223'/1'/0/0",
"xpub": "xpub",
"xpriv": "xpriv"
}
],
"curve": "secp256k1",
"publicKeyType": "secp256k1Extended",
"explorer": {
"url": "https://dashboard.internetcomputer.org",
"txPath": "/transaction/",
"accountPath": "/account/",
"sampleTx": "9e32c54975adf84a1d98f19df41bbc34a752a899c32cc9c0000200b2c4308f85",
"sampleAccount": "529ea51c22e8d66e8302eabd9297b100fdb369109822248bb86939a671fbc55b"
},
"info": {
"url": "https://internetcomputer.org",
"source": "https://github.com/dfinity/ic",
"rpc": "",
"documentation": "https://internetcomputer.org/docs"
}
}
]
85 changes: 69 additions & 16 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"tw_ethereum",
"tw_evm",
"tw_hash",
"tw_internet_computer",
"tw_keypair",
"tw_memory",
"tw_misc",
Expand Down
Loading

0 comments on commit 92fc9bd

Please sign in to comment.