All files / src/clarity/types bufferCV.ts

90% Statements 9/10
0% Branches 0/1
100% Functions 2/2
85.71% Lines 6/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1821x 21x             21x 43x       43x     25x  
import { ClarityType } from '../common/constants';
import { utf8ToBytes } from 'micro-stacks/common';
 
export interface BufferCV {
  readonly type: ClarityType.Buffer;
  readonly buffer: Uint8Array;
}
 
export const bufferCV = (buffer: Uint8Array): BufferCV => {
  Iif (buffer.length > 1000000) {
    throw new Error('Cannot construct clarity buffer that is greater than 1MB');
  }
 
  return { type: ClarityType.Buffer, buffer: Uint8Array.from(buffer) };
};
 
export const bufferCVFromString = (string: string): BufferCV => bufferCV(utf8ToBytes(string));