scure-btc-signer 위에 서수와 비문을 위한 최소 JS 라이브러리입니다.
JS 코드에서 라이브러리로 사용하거나 포함된 CLI 도구를 실행하세요. 비문을 사용하면 BTC 블록체인에 임의의 파일을 업로드할 수 있습니다.
실험적: 철저하게 테스트할 때까지 자금 손실이 발생할 수 있습니다.
npm은 마이크로서수를 설치합니다.
비문 만들기
타입스크립트 API
CLI
// npm 설치 마이크로 서수 @scure/btc-signer @scur/baseimport * as btc from '@scure/btc-signer';import * as ordinals from 'micro-ordinals';import { hex, utf8 } from '@ scure/base';const TESTNET = btc.utils.TEST_NETWORK;const privKey = hex.decode('0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a');const pubKey = btc.utils.pubSchnorr(privKey);const customScripts = [ordinals.OutOrdinalReveal]; // 외부에서 사용자 정의 스크립트 활성화// 이는 첫 번째 입력의 첫 번째 사토시에 새겨집니다. (기본값)const inscription = { Tags: {contentType: 'application/json', // 모든 형식 가능(MIME 유형)// ContentEncoding: 'br', // 압축: brotli만 지원됨 }, 본문: utf8.decode(JSON.stringify({ some: 1, test: 2, inscription: true, in: 'json' })), // 이전에 html에 삽입된 js 스크립트를 사용할 수 있습니다. // utf8.decode(`<html><head></head><body><script src="/content/script_inscription_id"></script>test</html>`)};const discoverPayment = btc.p2tr ( 정의되지 않음, // 내부PubKey ordinals.p2tr_ord_reveal(pubKey, [inscription]), // TaprootScriptTree TESTNET, // 메인넷 또는 테스트넷 false, // AllowUnknownOutputs, 안전 기능 customScripts // 사용자 정의 스크립트를 처리하는 방법);// 공개하기 전에 이 주소로 일부 비트코인을 보내야 합니다.// 또한 공개 tx를 감당할 만큼 충분해야 합니다. fee.console.log('Address',revealPayment.address) ; // 'tb1p5mykwcq5ly7y2ctph9r2wfgldq94eccm2t83dd58k785p0zqzwkspyjkp5'// 실수로 비문을 수수료로 보낼 수 있으니 각별히 주의하세요.// 또한 희귀도는 일반 지갑에서만 사용할 수 있습니다.// 하지만 이를 사용하여 다른 비문을 구문 분석하고 공통 비문을 만들 수 있습니다. const 변경 주소 = 공개결제.주소; // 다를 수 있음const discoverAmount = 2000n;const fee = 500n;const tx = new btc.Transaction({ customScripts });tx.addInput({ ...공개지불, // 이것은 우리가 보낸 비트코인이 포함된 tx의 txid입니다(교체). txid: '75ddabb27b8845f5247975c8a5ba7c6f336c4570708ebe230caf6db5217ae858', 인덱스: 0, WitnessUtxo: { 스크립트: 공개Payment.script, 금액: 공개Amount },});tx.addOutputAddress(changeAddr, 공개Amount - 수수료, TESTNET);tx.sign(privKey, 정의되지 않음, 새 Uint8Array(32));tx.finalize() ;const txHex = hex.encode(tx.extract());console.log(txHex); // 브로드캐스트로의 공개 tx의 16진수const tx2 = btc.Transaction.fromRaw(hex.decode(txHex)); // 비문 구문 분석console.log('parsed', ordinals.parseWitness(tx2.inputs[0].finalScriptWitness));console.log('vsize', tx2.vsize); // tx가 최소한 이만큼의 수수료를 지불해야 함을 밝힙니다.
import { Coder } from '@scure/base';import * as P from 'micro-packed';import { ScriptType, OptScript, CustomScript } from '@scure/btc-signer';type Bytes = Uint8Array;export 선언 const InscriptionId : P.Coder<string, Bytes>;type TagRaw = {tag: Bytes;data: Bytes;};declare const TagCoder: {pointer: P.CoderType<bigint>;contentType: P.CoderType<string>;parent: P.Coder<string, Uint8Array>;metadata: P.CoderType<any>;metaprotocol: P.CoderType<string>;contentEncoding: P.CoderType <string>;대리자: P.Coder<string, Uint8Array>;rune: P.CoderType<bigint>;참고: P.CoderType<string>;};내보내기 유형 Tags = Partial<{[TagCoder 유형의 키에 있는 K]: P.UnwrapCoder<(TagCoder 유형)[K]>;}> & {알 수 없음?: [바이트, 바이트][ ];};내보내기 유형 비문 = { 태그: 태그; 본문: 바이트; 저주받은?: 부울; };type OutOrdinalRevealType = { 유형: 'tr_ord_reveal'; 공개키: 바이트; 비문: 비문[]; };export 선언 const OutOrdinalReveal: Coder<OptScript, OutOrdinalRevealType | 정의되지 않음> & CustomScript;export 함수 선언 구문 분석(script: ScriptType, strict?: boolean): Inscription[] | 정의되지 않음;/** * tx 입력 감시 공개(tx.inputs[0].finalScriptWitness)에서 비문 구문 분석 */export 선언 함수parseWitness(witness: Bytes[]): Inscription[] | 정의되지 않음;/** * 공개 트랜잭션을 생성합니다. * 탭루트 스크립트를 공개하여 이 주소의 지출 출력에 대한 비문이 생성되었습니다. */export 선언 함수 p2tr_ord_reveal(pubkey: Bytes, inscriptions: Inscription[]): {type: string;script: Uint8Array;};
npm install -g 마이크로서수 ord file.jpg
사용법: ord [--net mainnet|testnet] [--priv key] [--recovery key] [--compress=on|off] [--fee 10.1] [--addr address]
net: 비트코인 네트워크
priv: WIF 형식의 탭루트 개인 키는 공개 거래에 사용됩니다. 지갑을 사용하지 마십시오. priv는 새 지갑이어야 합니다. 아무것도 제공되지 않은 경우 임시 키를 생성합니다.
복구: WIF 형식의 탭루트 개인 키를 사용하면 전체 등록 비용을 지불하지 않고도 실수로 비문 주소로 전송된 비트코인을 복구할 수 있습니다.
압축: brotli로 압축된 비문입니다. 탐험가와 호환됩니다. 기본값=켜짐
수수료: 사토시 단위의 비트코인 네트워크 수수료
addr: 공개 후 비문이 전송될 주소 중요: 첫 번째 sat은 항상 기재됩니다. 일괄 비문은 지원되지 않습니다.
네트워크 코드가 없습니다. 패키지를 더 안전하게 만들지만 개발자 경험이 줄어듭니다.
아마도 자동으로 수수료를 가져올 수 있지만 utxo 선택은 더욱 복잡해질 것입니다. 예를 들어 사용자가 이전에 무언가를 새겼거나 희귀한 서수가 있는 경우 이를 알기 위해 서수 노드에 액세스해야 합니다. 또한 우리는 지갑의 동결된 출력에 대해 아무것도 모릅니다. 이는 지갑 내부에만 있습니다.
명심해야 할 극단적인 경우:
사용자가 잘못된 txid/index를 추가했거나 전송 후 애플리케이션을 종료했습니다.
임시 개인 키를 인쇄하면 사용자는 '--priv'를 제공하여 다시 시작할 수 있습니다.
수수료/네트워크/경로가 동일하므로 프로세스를 다시 시작할 수 있습니다.
사용자가 금액보다 적거나 여러 개의 UTXO를 보냈습니다.
모든 지출에는 전체 가입비가 필요하기 때문에 실제로는 더 어렵습니다.
이를 위해 recovery
추가합니다.
mempool과 ordinalsbot을 사용하세요.
수도꼭지는 여러 개 있습니다: uo1, eu, 펌프
Mac에서 참새를 사용하려면:
open /Applications/Sparrow.app --args -n testnet
MIT (c) Paul Miller(https://paulmillr.com), LICENSE 파일을 참조하세요.