improve script hex parsing validation
This commit is contained in:
		
							parent
							
								
									0ce043cca9
								
							
						
					
					
						commit
						48b55eed46
					
				| @ -283,7 +283,10 @@ export function isFeatureActive(network: string, height: number, feature: 'rbf' | ||||
| } | ||||
| 
 | ||||
| export async function calcScriptHash$(script: string): Promise<string> { | ||||
|   const buf = Uint8Array.from(script.match(/.{1,2}/g).map((byte) => parseInt(byte, 16))); | ||||
|   if (!/^[0-9a-fA-F]*$/.test(script) || script.length % 2 !== 0) { | ||||
|     throw new Error('script is not a valid hex string'); | ||||
|   } | ||||
|   const buf = Uint8Array.from(script.match(/.{2}/g).map((byte) => parseInt(byte, 16))); | ||||
|   const hashBuffer = await crypto.subtle.digest('SHA-256', buf); | ||||
|   const hashArray = Array.from(new Uint8Array(hashBuffer)); | ||||
|   return hashArray | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user