diff --git a/cashtab/src/utils/__tests__/cashMethods.test.js b/cashtab/src/utils/__tests__/cashMethods.test.js --- a/cashtab/src/utils/__tests__/cashMethods.test.js +++ b/cashtab/src/utils/__tests__/cashMethods.test.js @@ -670,30 +670,30 @@ // push alias tx version const aliasProtocolVersionNumberHex = '00'; - // push the alias - const aliasHexBytes = '04'; // alias.length in one byte of hex - const aliasHex = Buffer.from(alias).toString('hex'); - // push the address const aliasAddressBytesHex = '15'; // (1 + 20) in one byte of hex const p2pkhVersionByteHex = '00'; + // push the alias + const aliasHexBytes = '04'; // alias.length in one byte of hex + const aliasHex = Buffer.from(alias).toString('hex'); + const aliasTxOpReturnOutputScript = [ opReturn, prefixBytesHex, aliasIdentifier, aliasProtocolVersionNumberHex, - aliasHexBytes, - aliasHex, aliasAddressBytesHex, p2pkhVersionByteHex, hash, + aliasHexBytes, + aliasHex, ].join(''); // Calculate the expected outputScript with the tested function const aliasOutputScript = generateAliasOpReturnScript(alias, address); // aliasOutputScript.toString('hex') - // 6a042e78656301000474657374150095e79f51d4260bc0dc3ba7fb77c7be92d0fbdd1d + // 6a042e78656300150095e79f51d4260bc0dc3ba7fb77c7be92d0fbdd1d0474657374 expect(aliasOutputScript.toString('hex')).toBe(aliasTxOpReturnOutputScript); }); @@ -712,30 +712,30 @@ // push alias tx version const aliasProtocolVersionNumberHex = '00'; - // push the alias - const aliasHexBytes = '07'; // alias.length in one byte of hex - const aliasHex = Buffer.from(alias).toString('hex'); - // push the address const aliasAddressBytesHex = '15'; // (1 + 20) in one byte of hex const p2shVersionByteHex = '08'; + // push the alias + const aliasHexBytes = '07'; // alias.length in one byte of hex + const aliasHex = Buffer.from(alias).toString('hex'); + const aliasTxOpReturnOutputScript = [ opReturn, prefixBytesHex, aliasIdentifier, aliasProtocolVersionNumberHex, - aliasHexBytes, - aliasHex, aliasAddressBytesHex, p2shVersionByteHex, hash, + aliasHexBytes, + aliasHex, ].join(''); // Calculate the expected outputScript with the tested function const aliasOutputScript = generateAliasOpReturnScript(alias, address); // aliasOutputScript.toString('hex') - // 6a042e7865630100077465737474776f1508d37c4c809fe9840e7bfa77b86bd47163f6fb6c60 + // 6a042e786563001508d37c4c809fe9840e7bfa77b86bd47163f6fb6c60077465737474776f expect(aliasOutputScript.toString('hex')).toBe(aliasTxOpReturnOutputScript); }); diff --git a/cashtab/src/utils/cashMethods.js b/cashtab/src/utils/cashMethods.js --- a/cashtab/src/utils/cashMethods.js +++ b/cashtab/src/utils/cashMethods.js @@ -676,9 +676,6 @@ // Per spec, push this as OP_0 script.push(0); - // Push alias to the stack - script.push(Buffer.from(alias, 'utf8')); - // Get the type and hash of the address in string format const { type, hash } = cashaddr.decode(address, true); @@ -696,6 +693,9 @@ // Push and script.push(Buffer.from(`${addressVersionByte}${hash}`, 'hex')); + // Push alias to the stack + script.push(Buffer.from(alias, 'utf8')); + return utxolib.script.compile(script); }; /* diff --git a/doc/standards/ecash-alias.md b/doc/standards/ecash-alias.md --- a/doc/standards/ecash-alias.md +++ b/doc/standards/ecash-alias.md @@ -39,12 +39,13 @@ ## Phase 1 details Aliases are registered by creating a "Registration Transaction" with the following properties: + 1. An output paying the required amount to a designated "Registration Address", and 2. An output with an OP_RETURN containing 4 data pushes: 1. A push of the 4-byte protocol identifier. 2. A push of a version number. - 3. A push of the Alias. - 4. A push of a CashAddr payload. This information defines the "Alias Address". + 3. A push of a CashAddr payload. This information defines the "Alias Address". + 4. A push of the Alias. ### The Registration Address