Where did this phrase originate from? What does this refer to? I know what it means, but does it originally mean walking off a ship on a sword along the edge as opposed to the flat?
There are multiple senses of the phrase "on edge," so to some extent it depends on what meaning you're referring to, but most senses appear to derive from the longer phrase set (a person's) teeth on edge.
According to OED, this is the earliest sense. First literally, meaning ‘to cause an unpleasant tingling in the teeth’, and then figuratively in the senses that will be outlined below. Uses in the literal sense are attested from 1382.
Ezek. xviii. 2 And the teeth of sones wexen on egge.
- The Wycliffite Bible (early version) · a1382
What exactly is meant by the earliest, literal uses of setting teeth on edge is a reasonable question. According to a note in OED:
It is not quite clear what is the precise notion originally expressed in this phrase. The earlier expression was to edge the teeth (see edge v.1 3); in the passage Ezek. xviii. 2 the Vulgate has obstupescere to be benumbed.
In other words, the earliest sense comes from a Latin Bible translation that might have meant to numb the teeth.
On edge in the first figurative sense, meaning full of eagerness, is attested from 1580:
on edge (said of ears, heart, teeth; also, to set): full of eagerness, all agog, ready.
An early example of this sense:
You will set mine eares on edge with sweet words.
- John Lyly · Sapho and Phao · (anon.) 1584
More recently, attested since 1872, "on edge" can mean to be excited or irritable.
Whitgift's strenuous hostility and unsparing rigour of argument set his opponent on edge.
- William Minto · A manual of English prose literature, biographical and critical · 1872
This use is frequent in contemporary English, so it's likely that this is the sense you are asking about. As you can see, it traces back through various meanings over time.
On edge with the connotation of nervous, irritable derives from an analogy of the cutting edge of instruments with one's feeling:
Tense, nervous, irritable, as in We were all on edge as we waited for the surgeon's report.
This expression transfers the edge of a cutting instrument to one's feelings. [Late 1800s ]
(The American Heritage® Idioms Dictionary)