29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Python/payment.py:
--------------------------------------------------------------------------------
1 | # pay 10.25 Pi
2 | from stellar_sdk import Server, Keypair, TransactionBuilder, Network
3 | from mnemonic import Mnemonic
4 | from keyfunc import account_keypair
5 | my_seed_phrase = 'passphrase' #you should add your secret key here
6 | my_passphrase = ''
7 | my_language = 'english' # or other language listed in
8 | # https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md
9 | mnemo = Mnemonic(my_language)
10 | if mnemo.check(my_seed_phrase):
11 | # my_seed_phrase is a valid BIP39 phrase for my_language
12 | binary_seed = Mnemonic.to_seed(my_seed_phrase, my_passphrase)
13 | account_number = 0 # an small unsigned integer (0 for the primary account)
14 | kp = account_keypair(binary_seed, account_number)
15 | source_keypair = Keypair.from_secret(kp.seed().decode())
16 | print(kp.seed().decode()) #it will show your original stellar key Like SXXX....
17 | des_address = "GBFA4NMHFUGHUV2QNGKNEFDS5IC64BWU5HDSWTDFI3EWRUPRXRRRFMPY" #destination address
18 | server = Server("https://api.testnet.minepi.com/")
19 | source_account = server.load_account(source_keypair.public_key)
20 | base_fee = server.fetch_base_fee()
21 | transaction = (
22 | TransactionBuilder(
23 | source_account=source_account,
24 | network_passphrase="Pi Testnet",
25 | base_fee=base_fee,
26 | )
27 | .add_text_memo("Hello, PiNetwork!")
28 | .append_payment_op(des_address, "10.25", "XLM") # xlm = native base on stellar sdk setting and will be pi in pi blockchain
29 | .build()
30 | )
31 | transaction.sign(source_keypair)
32 | response = server.submit_transaction(transaction)
33 |
--------------------------------------------------------------------------------
/Python/keyfunc.py:
--------------------------------------------------------------------------------
1 | import struct
2 | import hashlib
3 | import hmac
4 |
5 |
6 | # BIP-0044 path format for Stellar keypair derivation, as specified in
7 | # https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md
8 | ACCOUNT_PATH_FORMAT = "m/44'/314159'/0'"
9 |
10 |
11 | # the index of the first hardened key, per BIP-0032 and SLIP-0010
12 | HARDENED = 0x80000000
13 |
14 | # as defined in https://github.com/satoshilabs/slips/blob/master/slip-0010.md
15 | CURVE = b'ed25519 seed'
16 |
17 |
18 | hmac_sha_512 = lambda key, data: hmac.new(key, data, hashlib.sha512).digest()
19 |
20 |
21 | def key(v):
22 | """Return the private key part (the left half) of a 64-byte sequence v."""
23 | return v[:32]
24 |
25 |
26 | def chain_code(v):
27 | """Return the chain code part (the right half) of a 64-byte sequence v."""
28 | return v[32:]
29 |
30 |
31 | def ser32(i):
32 | """Serialize a 32-bit unsigned integer i as a 4-byte sequence.
33 | The most significant byte of i appears first in the serialization.
34 | """
35 | return struct.pack('>L', i)
36 |
37 |
38 | def new_master_key(seed):
39 | """Return the extended master key derived from a 64-byte binary seed.
40 |
41 | BIP-0032 defines an extended key as a pair (private_key, chain_code).
42 | The extended master key is the pair (master_private_key, master_chain_code)
43 | specified by SLIP-0010.
44 | """
45 | h = hmac_sha_512(CURVE, seed);
46 | return (key(h), chain_code(h))
47 |
48 |
49 | def derive(parent_key, parent_chain_code, i):
50 | """Return the i-th extended child key from an extended parent key."""
51 | assert len(parent_key) == 32
52 | assert len(parent_chain_code) == 32
53 | assert i >= HARDENED, 'no public derivation for ed25519'
54 | data = b'\x00' + parent_key + ser32(i)
55 | h = hmac_sha_512(parent_chain_code, data)
56 | return (key(h), chain_code(h))
57 |
58 |
59 | def derive_along_path(path, seed):
60 | """Derive an extended key from a 64-byte binary seed and a BIP-0044 path.
61 | Returns the extended key obtained by following the given derivation path,
62 | starting at the extended master key derived from the given binary seed.
63 | """
64 | elements = list(element.rstrip("'") for element in path.split('/'))[1:]
65 | (key, chain_code) = new_master_key(seed)
66 | for e in elements:
67 | (key, chain_code) = derive(key, chain_code, int(e) | HARDENED)
68 | return key
69 |
70 |
71 | def account_keypair(seed, account_number):
72 | """Return the account keypair for a 64-byte binary seed and account_number."""
73 | from stellar_base.keypair import Keypair
74 | acc_seed = derive_along_path(ACCOUNT_PATH_FORMAT, seed);
75 | return Keypair.from_raw_seed(acc_seed)
76 |
--------------------------------------------------------------------------------
/Python/AssetCreate.py:
--------------------------------------------------------------------------------
1 | from stellar_sdk import Server, Keypair, TransactionBuilder, Network, ManageSellOffer, Asset
2 | from mnemonic import Mnemonic
3 | import requests
4 | server = Server("https://api.testnet.minepi.com/")
5 | base_fee = server.fetch_base_fee()
6 | issuer_phrase = 'issuer passphrase' #need to change
7 | seller_phrase = 'seller passphrase' #need to change
8 | my_passphrase = ''
9 | my_language = 'english'
10 | mnemo = Mnemonic(my_language)
11 | if mnemo.check(issuer_phrase):
12 | issuer_seed = Mnemonic.to_seed(issuer_phrase, my_passphrase)
13 | if mnemo.check(seller_phrase):
14 | seller_seed = Mnemonic.to_seed(seller_phrase,my_passphrase)
15 | from keyfunc import account_keypair
16 | account_number = 0 # an small unsigned integer (0 for the primary account)
17 | issuer = account_keypair(issuer_seed, account_number)
18 | seller = account_keypair(seller_seed, account_number)
19 | seller_secret_key = Keypair.from_secret(seller.seed().decode())
20 | issuer_secret_key = Keypair.from_secret(issuer.seed().decode())
21 | issuer_public_key = issuer_secret_key.public_key
22 | seller_public_key = seller_secret_key.public_key
23 | issuer_account = server.load_account(account_id=issuer_public_key)
24 | seller_account = server.load_account(account_id=seller_public_key)
25 | #manage offer
26 | network_passphrase = "Pi Testnet"
27 | ## get fee from Pi Testnet
28 | fee = base_fee
29 | print("\nCreate new Asset\n")
30 | # create asset
31 |
32 | ## Create an object to represent the new asset
33 | asset_coin = Asset("PAPC", issuer_public_key) #You can change PAPC to what you want. Mention that the letters must<=12
34 |
35 | ## The Seller Account (the account that the custom asset receivs) must trust the asset.
36 | print(
37 | "The Seller Account must trust the new asset. \
38 | \nCreate Trust."
39 | )
40 | trust_transaction = (
41 | TransactionBuilder(
42 | source_account=seller_account,
43 | network_passphrase=network_passphrase,
44 | base_fee=fee,
45 | )
46 | # The `changeTrust` operation creates (or alters) a trustline
47 | # The `limit` parameter below is optional
48 | .append_change_trust_op(
49 | asset_code=asset_coin.code,
50 | asset_issuer=asset_coin.issuer,
51 | limit="5000", #this is the limit for your token, you can create more in future if your issuer account is not in lock status
52 | )
53 | .set_timeout(100)
54 | .build()
55 | )
56 |
57 | trust_transaction.sign(seller_secret_key)
58 | trust_transaction_resp = server.submit_transaction(trust_transaction)
59 | print("Trust created\n")
60 | ## Send 5000 PAPC asset to the seller account.
61 | print("Send PAPC to seller account")
62 | aac_payment_transaction = (
63 | TransactionBuilder(
64 | source_account=issuer_account,
65 | network_passphrase=network_passphrase,
66 | base_fee=fee,
67 | )
68 | .append_payment_op(
69 | destination=seller_public_key,
70 | amount="5000",
71 | asset_code=asset_coin.code,
72 | asset_issuer=asset_coin.issuer,
73 | )
74 | .build()
75 | )
76 | aac_payment_transaction.sign(issuer_secret_key)
77 | aac_payment_transaction_resp = server.submit_transaction(aac_payment_transaction)
78 | print(f"Sended 5000 PAPC to {seller_public_key}")
79 | print("#" * 30)
80 |
--------------------------------------------------------------------------------
/Token/script.js:
--------------------------------------------------------------------------------
1 | var pubkey
2 | var privkey
3 | async function key(){
4 | var mnemonics = { "english": new Mnemonic("english") };
5 | var mnemonic = mnemonics["english"];
6 | var phrase = document.getElementById('key').value;
7 | seed = mnemonic.toSeed(phrase, "");
8 | var path = "m/44'/314159'/0'";
9 | var keypair = libs.stellarUtil.getKeypair(path, seed);
10 | indexText = path;
11 | privkey = StellarSdk.Keypair.fromSecret(keypair.secret());
12 | pubkey = keypair.publicKey();
13 | document.getElementById("s0").innerHTML='解鎖';
14 | };
15 | async function trust() {
16 | const server = new StellarSdk.Server('https://api.testnet.minepi.com/');
17 | const fee = 100000;
18 | const account = await server.loadAccount(pubkey);
19 | console.log(fee);
20 | const trustchange = new StellarSdk.TransactionBuilder(account, {
21 | fee,
22 | networkPassphrase: 'Pi Testnet'
23 | })
24 | .addOperation(StellarSdk.Operation.changeTrust({
25 | asset: new StellarSdk.Asset('PAPC','GBFA4NMHFUGHUV2QNGKNEFDS5IC64BWU5HDSWTDFI3EWRUPRXRRRFMPY'),
26 | limit: '1',
27 | }))
28 | .setTimeout(100)
29 | .build();
30 | trustchange.sign(privkey);
31 | server.submitTransaction(trustchange);
32 | cooldown();
33 | document.getElementById("s1").innerHTML='已執行';
34 | }
35 | async function buy(){
36 | const server = new StellarSdk.Server('https://api.testnet.minepi.com/');
37 | const fee = 100000;
38 | account = await server.loadAccount(pubkey);
39 | const buyoffer = new StellarSdk.TransactionBuilder(account, {
40 | fee,
41 | // Uncomment the following line to build transactions for the live network. Be
42 | // sure to also change the horizon hostname.
43 | // networkPassphrase: StellarSdk.Networks.PUBLIC,
44 | networkPassphrase: 'Pi Testnet'
45 | })
46 | // Add a payment operation to the transaction
47 | .addOperation(StellarSdk.Operation.manageBuyOffer({
48 | selling:StellarSdk.Asset.native(),
49 | buying:new StellarSdk.Asset('PAPC','GBFA4NMHFUGHUV2QNGKNEFDS5IC64BWU5HDSWTDFI3EWRUPRXRRRFMPY'),
50 | buyAmount:'1',
51 | price:'1',
52 | }))
53 | // Make this transaction valid for the next 30 seconds only
54 | .setTimeout(100)
55 | // Uncomment to add a memo (https://www.stellar.org/developers/guides/concepts/transactions.html)
56 | // .addMemo(StellarSdk.Memo.text('Hello world!'))
57 | .build();
58 | buyoffer.sign(privkey);
59 | server.submitTransaction(buyoffer);
60 | cooldown();
61 | document.getElementById("s2").innerHTML='已執行';
62 | };
63 | async function sell(){
64 | const server = new StellarSdk.Server('https://api.testnet.minepi.com/');
65 | const fee = 100000;
66 | account = await server.loadAccount(pubkey);
67 | const buyoffer = new StellarSdk.TransactionBuilder(account, {
68 | fee,
69 | networkPassphrase: 'Pi Testnet'
70 | })
71 | .addOperation(StellarSdk.Operation.payment({
72 | destination:'GAHVUXJEP2BENC5AFGJI4XKTLPYO3TICGODOF5KTQV5BHWS3BBDLCC6O',
73 | asset: new StellarSdk.Asset('PAPC','GBFA4NMHFUGHUV2QNGKNEFDS5IC64BWU5HDSWTDFI3EWRUPRXRRRFMPY'),
74 | amount:'1',
75 | }))
76 | .setTimeout(100)
77 | .build();
78 | buyoffer.sign(privkey);
79 | server.submitTransaction(buyoffer);
80 | cooldown();
81 | document.getElementById("s3").innerHTML='已執行';
82 | };
83 | async function del_trust(){
84 | const server = new StellarSdk.Server('https://api.testnet.minepi.com/');
85 | const fee = 100000;
86 | account = await server.loadAccount(pubkey);
87 | const del_trust = new StellarSdk.TransactionBuilder(account, {
88 | fee,
89 | networkPassphrase: 'Pi Testnet'
90 | })
91 | .addOperation(StellarSdk.Operation.changeTrust({
92 | asset: new StellarSdk.Asset('PAPC','GBFA4NMHFUGHUV2QNGKNEFDS5IC64BWU5HDSWTDFI3EWRUPRXRRRFMPY'),
93 | limit: '0',
94 | }))
95 | .setTimeout(100)
96 | .build();
97 | del_trust.sign(privkey);
98 | server.submitTransaction(del_trust);
99 | cooldown();
100 | document.getElementById("s4").innerHTML='已執行';
101 | };
102 | function browse(){
103 | var link = 'https://pi-blockchain.net/account/'+pubkey;
104 | window.location.href=link;
105 | }
106 | function cooldown(){
107 | const b1 = document.getElementById('b1');
108 | const b2 = document.getElementById('b2');
109 | const b3 = document.getElementById('b3');
110 | const b4 = document.getElementById('b4');
111 | b1.disabled = true;
112 | b2.disabled = true;
113 | b3.disabled = true;
114 | b4.disabled = true;
115 | setTimeout(function(){
116 | b1.disabled = false;
117 | b2.disabled = false;
118 | b3.disabled = false;
119 | b4.disabled = false;
120 | },5000);
121 | }
122 |
--------------------------------------------------------------------------------
/Token/jsbip39.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013 Pavol Rusnak
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
5 | * this software and associated documentation files (the "Software"), to deal in
6 | * the Software without restriction, including without limitation the rights to
7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 | * of the Software, and to permit persons to whom the Software is furnished to do
9 | * so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | */
21 |
22 | /*
23 | * Javascript port from python by Ian Coleman
24 | *
25 | * Requires code from sjcl
26 | * https://github.com/bitwiseshiftleft/sjcl
27 | */
28 |
29 | var Mnemonic = function(language) {
30 |
31 | var PBKDF2_ROUNDS = 2048;
32 | var RADIX = 2048;
33 |
34 | var self = this;
35 | var wordlist = [];
36 |
37 | var hmacSHA512 = function(key) {
38 | var hasher = new sjcl.misc.hmac(key, sjcl.hash.sha512);
39 | this.encrypt = function() {
40 | return hasher.encrypt.apply(hasher, arguments);
41 | };
42 | };
43 |
44 | function init() {
45 | wordlist = WORDLISTS[language];
46 | if (wordlist.length != RADIX) {
47 | err = 'Wordlist should contain ' + RADIX + ' words, but it contains ' + wordlist.length + ' words.';
48 | throw err;
49 | }
50 | }
51 |
52 | self.generate = function(strength) {
53 | strength = strength || 128;
54 | var r = strength % 32;
55 | if (r > 0) {
56 | throw 'Strength should be divisible by 32, but it is not (' + r + ').';
57 | }
58 | var hasStrongCrypto = 'crypto' in window && window['crypto'] !== null;
59 | if (!hasStrongCrypto) {
60 | throw 'Mnemonic should be generated with strong randomness, but crypto.getRandomValues is unavailable';
61 | }
62 | var buffer = new Uint8Array(strength / 8);
63 | var data = crypto.getRandomValues(buffer);
64 | return self.toMnemonic(data);
65 | }
66 |
67 | self.toMnemonic = function(byteArray) {
68 | if (byteArray.length % 4 > 0) {
69 | throw 'Data length in bits should be divisible by 32, but it is not (' + byteArray.length + ' bytes = ' + byteArray.length*8 + ' bits).'
70 | }
71 |
72 | //h = hashlib.sha256(data).hexdigest()
73 | var data = byteArrayToWordArray(byteArray);
74 | var hash = sjcl.hash.sha256.hash(data);
75 | var h = sjcl.codec.hex.fromBits(hash);
76 |
77 | // b is a binary string, eg '00111010101100...'
78 | //b = bin(int(binascii.hexlify(data), 16))[2:].zfill(len(data) * 8) + \
79 | // bin(int(h, 16))[2:].zfill(256)[:len(data) * 8 / 32]
80 | //
81 | // a = bin(int(binascii.hexlify(data), 16))[2:].zfill(len(data) * 8)
82 | // c = bin(int(h, 16))[2:].zfill(256)
83 | // d = c[:len(data) * 8 / 32]
84 | var a = byteArrayToBinaryString(byteArray);
85 | var c = zfill(hexStringToBinaryString(h), 256);
86 | var d = c.substring(0, byteArray.length * 8 / 32);
87 | // b = line1 + line2
88 | var b = a + d;
89 |
90 | var result = [];
91 | var blen = b.length / 11;
92 | for (var i=0; i 0) {
214 | return null;
215 | }
216 | // idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic)
217 | var idx = [];
218 | for (var i=0; i
98 | * These objects are the currency accepted by SJCL's crypto functions.
99 | *
100 | *
101 | *
102 | * Most of our crypto primitives operate on arrays of 4-byte words internally,
103 | * but many of them can take arguments that are not a multiple of 4 bytes.
104 | * This library encodes arrays of bits (whose size need not be a multiple of 8
105 | * bits) as arrays of 32-bit words. The bits are packed, big-endian, into an
106 | * array of words, 32 bits at a time. Since the words are double-precision
107 | * floating point numbers, they fit some extra data. We use this (in a private,
108 | * possibly-changing manner) to encode the number of bits actually present
109 | * in the last word of the array.
110 | *
111 | *
112 | *
113 | * Because bitwise ops clear this out-of-band data, these arrays can be passed
114 | * to ciphers like AES which want arrays of words.
115 | *