Nghiên Cứu Công Nghệ Blockchain Và Ứng Dụng Trong Thương Mại Điện Tử.pdf

68 0 0
Nghiên Cứu Công Nghệ Blockchain Và Ứng Dụng Trong Thương Mại Điện Tử.pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

BỘ GIÁO DỤC VÀ ĐÀO TẠO UBND TỈNH THANH HÓA TRƯỜNG ĐẠI HỌC HỒNG ĐỨC LÊ PHI THƯỜNG NGHIÊN CỨU CÔNG NGHỆ BLOCKCHAIN VÀ ỨNG DỤNG TRONG THƯƠNG MẠI ĐIỆN TỬ LUẬN VĂN THẠC SĨ MÁY TÍNH THANH HÓA, NĂM 2022 BỘ G[.]

BỘ GIÁO DỤC VÀ ĐÀO TẠO UBND TỈNH THANH HÓA TRƯỜNG ĐẠI HỌC HỒNG ĐỨC LÊ PHI THƯỜNG NGHIÊN CỨU CÔNG NGHỆ BLOCKCHAIN VÀ ỨNG DỤNG TRONG THƯƠNG MẠI ĐIỆN TỬ LUẬN VĂN THẠC SĨ MÁY TÍNH THANH HĨA, NĂM 2022 BỘ GIÁO DỤC VÀ ĐÀO TẠO UBND TỈNH THANH HÓA TRƯỜNG ĐẠI HỌC HỒNG ĐỨC LÊ PHI THƯỜNG NGHIÊN CỨU CÔNG NGHỆ BLOCKCHAIN VÀ ỨNG DỤNG TRONG THƯƠNG MẠI ĐIỆN TỬ LUẬN VĂN THẠC SĨ MÁY TÍNH Chuyên ngành: Khoa học máy tính Mã số: 8480101 Người hướng dẫn khoa học: PGS.TS Trịnh Viết Cường THANH HÓA, NĂM 2022 Danh sách Hội đồng đánh giá luận văn Thạc sỹ khoa học (Theo Quyết định số: /QĐ- ĐHHĐ ngày tháng năm 2022 Hiệu trưởng Trường Đại học Hồng Đức) Học hàm, học vị Cơ quan Chức danh Họ tên Công tác Hội đồng Chủ tịch HĐ UV, Phản biện UV, Phản biện Uỷ viên Uỷ viên, Thư ký Xác nhận Người hướng dẫn Học viên chỉnh sửa theo ý kiến Hội đồng Ngày tháng năm 2022 LỜI CAM ĐOAN Tôi xin cam đoan Luận văn “Nghiên cứu công nghệ Blockchain ứng dụng thương mại điện tử” cơng trình nghiên cứu riêng dưới sự hướng dẫn PGS.TS Trịnh Viết Cường Luận văn không trùng lặp với khóa luận, luận văn, luận án cơng trình nghiên cứu cơng bố Thanh Hố, ngày 12 tháng9 năm 2022 Người cam đoan Lê Phi Thường LỜI CẢM ƠN Đề tài “Nghiên cứu công nghệ Blockchain ứng dụng thương mại điện tử” nội dung chọn để nghiên cứu làm luận văn tốt nghiệp sau i hai năm theo học chương trình cao học chuyên ngành Khoa học máy tính trường Đại học Hồng Đức Để hồn thành q trình nghiên cứu hồn thiện luận văn này, lời tơi xin chân thành cảm ơn sâu sắc đến thầy giáo PGS.TS Trịnh Viết Cường thuộc Khoa Công Nghệ thông tin Truyền thông – Trường Đại học Hồng Đức, thầy trực tiếp bảo hướng dẫn suốt q trình nghiên cứu để tơi hồn thiện luận văn Nhân dịp này, xin cảm ơn Khoa Công Nghệ thông tin Truyền thông, Trường Đại học Hồng Đức, lãnh đạo anh chị công tác khoa tạo điều kiện thời gian cho tơi suốt q trình nghiên cứu Cuối cùng, xin cảm ơn người thân, bạn bè ln bên tơi, động viên tơi hồn thành khóa học luận văn Trân trọng cảm ơn! Thanh Hoá, ngày 12 tháng năm 2022 Tác giả Lê Phi Thường MỤC LỤC LỜI CAM ĐOAN…………………………………………………………….i LỜI CẢM ƠN……………………………………………………………….ii MỤC LỤC………………………………………………………………… iii DANH MỤC VIẾT TẮT…………………………………………………….v DANH MỤC HÌNH…………………………………………………………vi MỞ ĐẦU ii Lý chọn đề tài Mục tiêu nghiên cứu Nội dung nghiên cứu Tổng quan luận văn Chương GIỚI THIỆU TỔNG QUAN VỀ CÔNG NGHỆ BLOCKCHAIN VÀ THƯƠNG MẠI ĐIỆN TỬ…………………………………………… ….3 1.1 Giới thiệu chung công nghệ Blockchain 1.2 Thương mại điện tử 1.2.1 Thanh toán điện tử 11 1.2.2 Tiền điện tử 12 Kết luận chương 14 Chương GIẢI PHÁP KỸ THUẬT XÂY DỰNG ỨNG DỤNG THƯƠNG MẠI ĐIỆN TỬ 15 2.1 Bài toán xây dựng hệ thống thương mại điện tử 15 2.2 Hyperledger Fabirc……………………………………………………………17 2.2.1 Cấu trúc mạng Hyperledger Fabric 17 2.2.2 Các thành phần Hyperledger Fabric 25 2.2.3 Cài đặt lưu trữ liệu sổ 33 Kết luận chương 37 Chương XÂY DỰNG ỨNG DỤNG THƯƠNG MẠI ĐIỆN TỬ DỰA TRÊN CÔNG NGHỆ BLOCKCHAIN…………….…….………………… 38 3.1 Các chức cài đặt thử nghiệm hệ thống 38 3.2 Cài đặt hệ thống 38 3.2.1 Cài đặt công cụ cần thiết 38 3.2.2 Xây dựng hệ thống Blockchain 40 3.2.3 Xây dựng hệ thống tiền điện tử 44 3.3 Một số hình ảnh giao diện 50 Kết luận chương 54 iii KẾT LUẬN 55 TÀI LIỆU THAM KHẢO 56 DANH MỤC CÁC KÝ HIỆU, CÁC TỪ VIẾT TẮT Các từ viết tắt Nghĩa tiếng Anh BLOCK BTC Nghĩa tiếng Việt Khối Một loại tiền ảo Bitcoin iv ECDSA Elliptic Curve Digital Signature Algorithm Hệ chữ ký điện tử ECDSA POS Proof of Work Bằng chứng công việc POW Proof of Stake Bằng chứng cổ phần Node có đầy đủ chức FULL NODE Node có chức đào MINER NODE tiền ảo Node sử dụng dịch vụ hệ CLIENT NODE SHA thống Secure Hash Algorithm Họ hàm băm SHA BLOCKCHAIN Chuỗi khối TMĐT Thương mại điện tử TTĐT Thanh tốn điện tử DANH MỤC HÌNH Hình 1.1: Chuỗi khối Blockchain (nguồn linkedin.com) Hình 2.1: Kiến trúc mạng mạng Blockchain Hyperledger Fabric 17 Hình 2.2: Khởi tạo mạng ban đầu với Order node 18 Hình 2.3 : Thêm cấu hình mạng (nguồn hyperledger.org) 19 v CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperle dger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org 2.example.com/tls/ca.crt peer channel join -b mychannel.block Update Anchor Peer cho Org Bước giống bước trên, ta phải đặt lại biến môi trường CLI để chúng tương ứng với Anchor Peer Org update Các lệnh sau update anchor peer Org: Org1: CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/ fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.e xample.com/msp CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_LOCALMSPID="Org1MSP" CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperle dger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org 1.example.com/tls/ca.crt peer channel update -o orderer.certificate.com:7050 -c mychannel -f /channelartifacts/Org1MSPanchors.tx Org2: CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/ fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.e xample.com/msp CORE_PEER_ADDRESS=peer0.org2.example.com:9051 CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperle dger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org 2.example.com/tls/ca.crt peer channel update -o orderer.certificate.com:7050 -c mychannel -f /channelartifacts/Org2MSPanchors.tx 43 3.2.3 Xây dựng hệ thống tiền điện tử Viết smart contract cho chức giao dịch Đầu tiên cần phải cài đặt module cần thiết: fabric-contract-api : cung cấp api cấp cao để triển khai smart contract npm install fabric-contract-api crypto-js: Thư viện JavaScript tiêu chuẩn tiền điện tử npm install crypto-js Ví dụ cấu trúc UTXO (giao dịch chưa tiêu): { ID: “ ”, ParentTransactionId: “ ”, Recipient: “ “, Sender: “ “, Value: “ “, Staus: “ ”, timeStamp: “ ”, } Trong đó: ID: id giao dịch ParentTransactionId: id giao dịch cha Recipient: địa ví người nhận Sender: địa ví người gửi Value: số tiền giao dịch Status: trạng thái giao dịch timeStamp: mốc thời gian giao dịch Hàm thực chức truy vấn Utxo id : async queryUtxo(ctx, id){ const utxoJSON = await ctx.stub.getState(id); // get the asset from chaincode state 44 if (!utxoJSON || utxoJSON.length === 0) { throw new Error(`The utxo ${id} does not exist`); } return utxoJSON.toString(); } Hàm thực chức truy vấn tất utxo có sổ cái: async queryAllUtxos(ctx) { const startKey = ''; const endKey = ''; const allResults = []; for await (const {key, value} of ctx.stub.getStateByRange(startKey, endKey)) { const strValue = Buffer.from(value).toString('utf8'); let record; try { record = JSON.parse(strValue); } catch (err) { console.log(err); record = strValue; } allResults.push({ Key: key, Record: record }); } return JSON.stringify(allResults); } Hàm thực chức truy vấn tất utxo địa ví: async queryUtxosOfWallet(ctx) { const wa= ctx.clientIdentity.getAttributeValue('wallet_address'); const startKey = ''; 45 const endKey = ''; const allResults = []; for await (const {key, value} of ctx.stub.getStateByRange(startKey, endKey)) { const strValue = Buffer.from(value).toString('utf8'); let record; try { record = JSON.parse(strValue); } catch (err) { console.log(err); record = strValue; } if(record.Recipient==wa||record.Sender==wa) allResults.push({ Key: key, Record: record }); } console.info(allResults); return JSON.stringify(allResults); } Hàm thực chức chuyển tiền từ địa ví người gửi đến địa ví người nhận: async tranferMoney(ctx, sender, recipient, inputs, value){ const wa= ctx.clientIdentity.getAttributeValue('wallet_address'); if(sender!=wa){ throw new Error("Sender is invalid!"); } let totalValue = 0; let error = false; for(const input of inputs){ const utxoAsBytes = await ctx.stub.getState(input.ID); 46 if (!utxoAsBytes || utxoAsBytes.length === 0) { error = true; throw new Error(`${utxo.ID} does not exist`); }else{ const strValue = Buffer.from(utxoAsBytes).toString('utf8'); const tmp = JSON.parse(strValue); if(tmp.Recipient==wa){ totalValue+= tmp.Value; } } } if(!error&&totalValue>=value){ for(const input of inputs){ const utxoAsBytes = await ctx.stub.getState(input.ID); const mUtxo = JSON.parse(utxoAsBytes.toString()); mUtxo.Status=1; awaitctx.stub.putState(input.ID, Buffer.from(JSON.stringify(mUtxo))); } const date = new Date(); const currentTime =date.getTime().toString(); const idTrans1= sender+recipient+value.toString()+currentTime; const num1Tras={ ID: SHA256(idTrans1).toString(), ParentTransactionId: 'hsajdl', Recipient: recipient, Sender: sender, Value: value, Status: 0, 47 timeStamp: currentTime, }; awaitctx.stub.putState(num1Tras.ID, Buffer.from(JSON.stringify(num1Tras))); const change = totalValue-value; if(change>0){ const idTrans2= sender+sender+change.toString()+currentTime; const num2Tras={ ID: SHA256(idTrans2).toString(), ParentTransactionId: 'hsajdl', Recipient: sender, Sender: sender, Value: change, Status: 0, timeStamp: currentTime, }; awaitctx.stub.putState(num2Tras.ID, Buffer.from(JSON.stringify(num2Tras))); } }else{ throw new Error('Invalid transaction!'); } } Triển khai smart contract cho kênh Đóng gói smart contract export PATH=${PWD}/ /bin:$PATH export FABRIC_CFG_PATH=$PWD/ /config/ peer lifecycle chaincode package .tar.gz path lang node label basic_1.0 48 Cài đặt chaincode lên Peer export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrgani zations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizatio ns/org1.example.com/users/Admin@org1.example.com/msp export CORE_PEER_ADDRESS=localhost:7051 peer lifecycle chaincode install .tar.gz Phê duyệt chaincode export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizatio ns/org1.example.com/users/Admin@org1.example.com/msp export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrgani zations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt export CORE_PEER_ADDRESS=localhost:7051 peer lifecycle chaincode approveformyorg -o localhost:7050 ordererTLSHostnameOverride orderer.example.com channelID name version 1.0 package-id $CC_PACKAGE_ID sequence tls cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer example.com/msp/tlscacerts/tlsca.example.com-cert.pem" 49 Cam kết chaincode lên kênh peer lifecycle chaincode commit -o localhost:7050 ordererTLSHostnameOverride orderer.example.com channelID name version 1.0 sequence tls cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.e xample.com/msp/tlscacerts/tlsca.example.com-cert.pem" peerAddresses localhost:7051 tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org 1.example.com/tls/ca.crt" peerAddresses localhost:9051 tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org 2.example.com/tls/ca.crt" 3.3 Một số hình ảnh giao diện Do hệ thống Blockchain chạy ngầm định hệ thống luận văn đưa số hình ảnh giao diện hệ thống tiền điện tử Trong trang Home có mục sau để người dùng thao tác: Transfer: Đây mục để người dùng thực thao tác chuyển tiền đến địa ví khác Acount: Đây mục để người dùng xem số dư có tài khoản xem lịch sử thực giao dịch Bank: Đây mục để người dùng thực chức đăng ký tạo chứng thực, chức liên quan đến ngân hàng 50 Hình 3.1: Giao diện trang Home người dùng Trong trang Bank phần tạo địa ví: Có nút chức để người dùng đăng ký, tạo mới địa import địa ví sẳn có vào để thực giao dịch Có khung hiển thị cặp khóa cơng khai bí mật mới tạo có nút để lưu chúng xuống máy người dùng 51 Hình 3.2: Giao diện đăng ký khởi tạo địa ví trang Transfer Trang Transfer: ToAddress: mục để nhập địa ví người nhận Amount to Send: mục để nhập số tiền cần chuyển Your Private Key: mục để nhập khóa bí mật người dùng để thực ký lên giao dịch Generate Transaction: nút để thực gửi giao dịch 52 Hình 3.3: Giao diện chuyển tiền đến địa ví khác hệ thống Trang Account: You Wallet Address: Mục để hiển thị địa ví sử dụng Amount: mục hiển thị tổng số tiền có tài khoản Trasaction history: mục hiển thị lịch sử giao dịch ví Hình 3.4: Giao diện kiểm tra số dư tài khoản lịch sử giao dịch 53 Kết luận chương Trong chương luận văn trình bày trình xây dựng thực nghiệm ứng dụng thương mại điện tử có hỗ trợ tiền điện tử dựa tảng mã nguồn mở Hyperledger Fabric Cụ thể luận văn trình bày việc xây dựng hai vấn đề xây dựng hệ thống Blockchain xây dựng hệ thống tiền điện tử dựa tảng mã nguồn mở Hyperledger Fabric Để hệ thống vào thực tế ta cần xây dựng thêm chức Website hệ thống thương mại điện tử thông thường chức quản lý hàng hóa, giỏ hàng, … 54 KẾT LUẬN Xây dựng hệ thống thương mại điện tử có hỗ trợ hệ thống toán online nhu cầu cần thiết doanh nghiệp Các hệ thống thương mại điện tử với kỹ thuật truyền thống dựa sở liệu tập trung toán dựa vào bên thứ ba (ngân hàng) lộ rõ nhiều bất cập an tồn, phí giao dịch lớn, … Công nghệ Blockchain đời gần với hệ thống tiền điện tử xây dựng dựa xem giải pháp tối ưu để khắc phục bất cập phương pháp truyền thống Cụ thể hệ thống Blockchain với đặc tính an tồn giải vấn đề an toàn sở liệu tập trung, hệ thống tiền điện tử đem lại giải pháp tốn linh động giảm chi phí Trong luận văn học viên trình bày vấn đề thương mại điện tử, trình bày giải pháp để xây dựng hệ thống thương mại điện tử có tốn online tiền điện tử, dựa công nghệ Blockchain để giải bất cập công nghệ cũ Luận văn trình bày việc cài đặt thực nghiệm giải pháp công nghệ này, cụ thể dựa tảng mả nguồn mở Hyperledger Fabric để xây dựng mạng Blockchain hệ thống tiền điện tử 55 TÀI LIỆU THAM KHẢO [1] A Kiayias, A Russel, B David, and R Oliynycov (2018), “Ouroburos: A provably secure proof-of-stake protocol”, Eurocrypt [2] Androulaki, Elli; Barger, Artem; Bortnikov, Vita; Cachin, Christian; Christidis, Konstantinos; De Caro, Angelo; Enyeart, David; Ferris, Christopher; Laventman, Gennady; Manevich, Yacov; Muralidharan, Srinivasan; Murthy, Chet; Nguyen, Binh; Sethi, Manish; Singh, Gari; Smith, Keith; Sorniotti, Alessandro; Stathakopoulou, Chrysoula; Vukolić, Marko; Weed Cocco, Sharon; Yellick, Jason (2018), Hyperledger Fabric: A Distributed Operating System for Permissioned Blockchains, arXiv:1801.10228 doi:10.1145/3190508.3190538 [3] Bandara, H M N D; A P Jayasumana (2012), "Collaborative Applications over Peer-to-Peer Systems – Challenges and Solutions", Peer-to-Peer Networking and Applications [4] Cope, James (2002), "What's a Peer-to-Peer (P2P) Network?", Computerworld [5] Dmitry Khovratovich, Christian Rechberger & Alexandra Savelieva (2011), "Bicliques for Preimages: Attacks on Skein-512 and the SHA-2 family", IACR Cryptology ePrint Archive [6] Daniel R L Brown, SECG SEC 1: Elliptic Curve Cryptography (Version 2.0) https://www.secg.org/sec1-v2.pdf [7] Dimitris Karakostas, Aggelos Kiayias, and Mario Larangeira (2020), “Account Management in Proof of Stake Ledgers”, IACR Cryptol, ePrint Arch [8] "Founder of the Apache Software Foundation Joins Linux Foundation to Lead Hyperledger Project", 2016-05-19, Archived from the original on 2016-06-10 [9] Hyperledger (2016), “Open Source Blockchain Effort for the Enterprise Elects Leadership Positions and Gains New Investments”, Hyperledger, 2016-03-29, Retrieved 2018-04-28 56 [10] Ji Chen and Silvio Micali (2019), “Algorand”, Theoretical Computer Science (TCS), vol 777 [11] Johnson, Don; Menezes, Alfred (1991), “The Elliptic Curve Digital Signature Algorithm (ECDSA)", CiteSeerX, 10.1.1.38.8014 [12] "Linux Foundation's Hyperledger Project Announces 30 Founding Members and Code Proposals To Advance Blockchain Technology", 2016-0209, Archived from the original on 2016-02-25, Retrieved 2016-02-17 [13] Mario Lamberger & Florian Mendel (2011), Higher-Order Differential Attack on Reduced SHA-256 [14] Rüdiger Schollmeier (2002), "A Definition of Peer-to-Peer Networking for the Classification of Peer-to-Peer Architectures and Applications”, Proceedings of the First International Conference on Peer-to-Peer Computing, IEEE [15] RFC 6979 - Deterministic Usage of the Digital Signature Algorithm (DSA) and Elliptic Curve Digital Signature Algorithm (ECDSA) [16] Rivest, R.; Shamir, A.; Adleman, L (1978), "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", ACM [17] Rivest, Ronald (2011), The Early Days of RSA – History and Lessons [18].Somitra Kumar Sanadhya & Palash Sarkar (2008), New Collision Attacks Against Up To 24-step SHA-2 [19] Satoshi Nakamoto (2008), Bitcoin: A Peer-to-Peer Electronic Cash System [20] The Linux Foundation (2018), “Linux Foundation Unites Industry Leaders to Advance Blockchain Technology”, The Linux Foundation 2015-12- 17, Archived from the original on 2017-07-17 57

Ngày đăng: 17/07/2023, 23:21

Tài liệu cùng người dùng

Tài liệu liên quan